我是新手,如果我的问题很愚蠢,请承担.
int main()
{
int x=60674;
printf("%lf \n",(double)(x*x));
printf("%lld \n",(long long)(x*x));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?
在以下结构定义中:http://elixir.free-electrons.com/linux/latest/source/include/uapi/linux/serial.h#L116 我发现了这个:
struct serial_rs485 {
__u32 flags; /* RS485 feature flags */
#define SER_RS485_ENABLED (1 << 0) /* If enabled */
#define SER_RS485_RTS_ON_SEND (1 << 1) /* Logical level for RTS pin when sending */
#define SER_RS485_RTS_AFTER_SEND (1 << 2) /* Logical level for RTS pin after sent*/
#define SER_RS485_RX_DURING_TX (1 << 4)
#define SER_RS485_TERMINATE_BUS (1 << 5) /* Enable bus termination (if supported) */
__u32 delay_rts_before_send; /* Delay before send (milliseconds) */
__u32 delay_rts_after_send; /* Delay …Run Code Online (Sandbox Code Playgroud) 以下程序显示了如何在C程序中构建二叉树.它使用动态内存分配,指针和递归.二叉树是一种非常有用的数据结构,因为它允许在排序列表中进行有效的插入,搜索和删除.因为这样的树本质上是递归定义的结构,递归编程是处理它的自然而有效的方式.
tree
empty
node left-branch right-branch
left-branch
tree
right-branch
tree
Run Code Online (Sandbox Code Playgroud)
这是代码:
#include <stdlib.h>
#include <stdio.h>
struct tree_el {
int val;
struct tree_el * right, * left;
};
typedef struct tree_el node;
void insert(node ** tree, node * item) {
if(!(*tree)) {
*tree = item;
return;
}
if(item->val<(*tree)->val)
insert(&(*tree)->left, item);
else if(item->val>(*tree)->val)
insert(&(*tree)->right, item);
}
void printout(node * tree) {
if(tree->left) printout(tree->left);
printf("%d\n",tree->val);
if(tree->right) printout(tree->right);
}
void main() {
node * curr, * root;
int i;
root = NULL;
for(i=1;i<=10;i++) { …Run Code Online (Sandbox Code Playgroud) 这在C中意味着什么:
char strings[USHRT_MAX][50];
Run Code Online (Sandbox Code Playgroud)
它是否创建了一个称为字符串的锯齿状字符数组?
这将导致尝试除以零时产生错误,如果该错误未被语言的错误处理功能捕获,则可能会发生意外结果:
static void aspect_adjust_packed4444_scanline_c( uint8_t *output,
uint8_t *input,
int width,
double pixel_aspect )
{
double i;
int prev_i = 0;
int w = 0;
pixel_aspect = 1.0 / pixel_aspect;
for( i = 0.0; i < width; i += pixel_aspect )
{
uint8_t *curin = input + ((int) i)*4;
if( !prev_i )
{
output[ 0 ] = curin[ 0 ];
output[ 1 ] = curin[ 1 ];
output[ 2 ] = curin[ 2 ];
output[ 3 ] = curin[ 3 ]; …Run Code Online (Sandbox Code Playgroud) var x int
done := false
go func() { x = f(...); done = true }
while done == false { }
Run Code Online (Sandbox Code Playgroud)
这是一个 Go 代码片段。我的朋友告诉我这是UB代码。为什么?
我正在运行GTK教程中的"hello-world"代码:
#include <gtk/gtk.h>
int main(int argc, char* argv[])
{
GTKWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
gtk_main();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我使用以下方法编译它时,我收到此错误:
$ gcc base.c -o base `pkg-config --cflags --libs gtk+-2.0`
base.c: In function ‘main’:
base.c:5:2: error: unknown type name ‘GTKWidget’
GTKWidget *window;
Run Code Online (Sandbox Code Playgroud)
似乎问题不是gtk.h没有包含在内,而是说GTKWidget不是一个东西?
有人可以帮我解决这个问题吗?
不删除在下面的行(*)上分配的内存.
void f() {
int z = *new int; // (*)
//...
}
Run Code Online (Sandbox Code Playgroud)
不改变行上的代码(*),有什么办法可以避免泄漏内存?如果是这样,怎么样?如果没有,为什么不呢?
我不明白的是,什么*new int意思?具体来说,添加*旁边的新意味着什么呢?
另外,如果不是int z,我们有int &z什么?