void main() {
int num;
num = 1;
num++;
num = num + 9;
printf('%u',num);
}
What is wrong with this? It says segmentation fault. Written in C.
void main() {
int num;
num = 1;
num++;
num = num + 9;
printf('%u',num);
}
What is wrong with this? It says segmentation fault. Written in C.
'%u' should be "%u" (double quotes). C is not SQL, and '%u' is considered a multicharacter literal.
And as Erik said, %d is better in your case.
printf("%d") - printf takes a C string not a character. %d is the correct format specifier for an integer.
That '%u' ( a multi-character char constant) should be "%u" (a char array). The char constant is being misinterpreted as a pointer to random memory.
Note that you would have gotten an error from passing the wrong type (int instead of const char *) as the first argument of printf, except that you forgot to #include <stdio.h> or prototype printf yourself. And since printf is a variadic function, this results in UB too.