Output of the Program | Use Macros Carefully! Last Updated : 21 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Predict the output of the below program C++ #include <iostream> using namespace std; #define square(x) x*x int main() { int x; x = 36 / square(6); cout << x; return 0; } // This code is contributed by sarajadhav12052009 C #include <stdio.h> #define square(x) x*x int main() { int x; x = 36/square(6); printf("%d",x); getchar(); return 0; } Output36 Explanation: Preprocessor replaces square(6) by 6*6 and the expression becomes x = 36/6*6 and value of x is calculated as 36. If we want correct behavior from macro square(x), we should declare it as #define square(x) ((x)*(x)) /* Note that the expression (x*x) will also fail for square(6-2) */ Comment More infoAdvertise with us Next Article Output of the Program | Use Macros Carefully! K kartik Follow Improve Article Tags : C Language cpp-macros C-Output Similar Reads 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 programs | Set 8 Predict the output of below C programs. Question 1: c #include<stdio.h> int main() { int x = 5, p = 10; printf("%*d", x, p); getchar(); return 0; } Output: 10 Explanation: Please see standard printf function definition int printf ( const char * format, ... ); format: String that cont 3 min read 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 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 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 Like