Output of C Program | Set 17 Last Updated : 31 Jul, 2018 Comments Improve Suggest changes Like Article Like Report Predict the output of following C programs. Question 1 C #include<stdio.h> #define R 10 #define C 20 int main() { int (*p)[R][C]; printf("%d", sizeof(*p)); getchar(); return 0; } Output: 10*20*sizeof(int) which is "800" for compilers with integer size as 4 bytes. The pointer p is de-referenced, hence it yields type of the object. In the present case, it is an array of array of integers. So, it prints R*C*sizeof(int). Thanks to Venki for suggesting this solution. Question 2 C #include<stdio.h> #define f(g,g2) g##g2 int main() { int var12 = 100; printf("%d", f(var,12)); getchar(); return 0; } Output: 100 The operator ## is called "Token-Pasting" or "Merge" Operator. It merges two tokens into one token. So, after preprocessing, the main function becomes as follows, and prints 100. C int main() { int var12 = 100; printf("%d", var12); getchar(); return 0; } Question 3 C #include<stdio.h> int main() { unsigned int x = -1; int y = ~0; if(x == y) printf("same"); else printf("not same"); printf("\n x is %u, y is %u", x, y); getchar(); return 0; } Output: "same x is MAXUINT, y is MAXUINT" Where MAXUINT is the maximum possible value for an unsigned integer. -1 and ~0 essentially have same bit pattern, hence x and y must be same. In the comparison, y is promoted to unsigned and compared against x. The result is "same". However, when interpreted as signed and unsigned their numerical values will differ. x is MAXUNIT and y is -1. Since we have %u for y also, the output will be MAXUNIT and MAXUNIT. Thanks to Venki for explanation. Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above Comment More infoAdvertise with us Next Article Output of C Program | Set 17 kartik Follow Improve Article Tags : C Language C-Output Similar Reads Output of C Programs | Set 1 Predict the output of below programs. Question 1c#include<stdio.h> int main() { int n; for(n = 7; n!=0; n--) printf("n = %d", n--); getchar(); return 0; }Output: Above program goes in infinite loop because n is never zero when loop condition (n != 0) is checked.Question 2c #include<stdio.h 2 min read Output of C Program | Set 27 Predict the output of following C programs. Question 1 C #include <stdio.h> int main(void) { int i; int power_of_ten[5] = { 00001, 00010, 00100, 01000, 10000, }; for (i = 0; i < 5; ++i) printf("%d ", power_of_ten[i]); printf("\n"); return 0; } In the above example, we ha 3 min read Output of C Program | Set 21 Predict the output of following C programs. Question 1 C #include<stdio.h> #define fun (x) (x)*10 int main() { int t = fun(5); int i; for(i = 0; i < t; i++) printf("GeeksforGeeks\n"); return 0; } Output: Compiler Error There is an extra space in macro declaration which causes fun 2 min read Output of C Program | Set 18 Predict the output of following C programs.Question 1 C #include<stdio.h> int fun() { static int num = 40; return num--; } int main() { for(fun(); fun(); fun()) { printf("%d ", fun()); } getchar(); return 0; } Output: 38 35 32 29 26 23 20 17 14 11 8 5 2Since num is static in fun(), t 2 min read Output of C Program | Set 19 Predict the outputs of following program. Difficulty Level: Rookie Question 1 C #include <stdio.h> int main() { int a = 10, b = 20, c = 30; if (c > b > a) { printf("TRUE"); } else { printf("FALSE"); } getchar(); return 0; } Output: FALSE Let us consider the condition 1 min read Output of C Programs | Set 7 Predict the output of below programsQuestion 1 c int main() { int i = 0; while (i <= 4) { printf("%d", i); if (i > 3) goto inside_foo; i++; } getchar(); return 0; } void foo() { inside_foo: printf("PP"); } Output: Compiler error: Label "inside_foo" used but not defined.Expl 2 min read Output of C programs | Set 37 1.) What will be the output of the following code? C #include <stdio.h> int main(void) { int y, z; int x = scanf("%d %d", &y, &z); printf("%d", x); return 0; } Input: 12 10 a)12 b)2 c)Syntax Error d)10 Answer : b Explanation: scanf() returns the number of variables 3 min read Output of C programs | Set 51 1. What will be the output of the below program? CPP #include <stdio.h> int main() { printf("%d", printf("%d", printf("%d", printf("%s", "Welcome to geeksforgeeks")))); return (0); } Options: 1. Welcome to geeksforgeeks2531 2. Welcome to geeksf 2 min read Output of C Programs | Set 16 Predict the output of below C programs. Question 1 C #include <stdio.h> char* fun() { return "awake"; } int main() { printf("%s",fun()+ printf("I see you")); getchar(); return 0; } Output: Some string starting with "I see you" Explanation: (Thanks to Venki for sug 2 min read Output of C Programs | Set 14 Predict the output of below C programs. Question 1 C #include<stdio.h> int main() { int a; char *x; x = (char *) &a; a = 512; x[0] = 1; x[1] = 2; printf("%d\n",a); getchar(); return 0; } Answer: The output is dependent on endianness of a machine. Output is 513 in a little endian 2 min read Like