Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Output of C Program | Set 21

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 to be replaced by (x). If we remove the extra space then program works fine and prints “GeeksforGeeks” 50 times. Following is the working program. 

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;
}


Be careful when dealing with macros. Extra spaces may lead to problems. 
Question 2 

C




#include<stdio.h>
int main()
{
    int i = 20,j;
    i = (printf("Hello"), printf(" All Geeks "));
    printf("%d", i);
  
    return 0;
}


Output: Hello All Geeks 11 The printf() function returns the number of characters it has successfully printed. The comma operator evaluates it operands from left to right and returns the value returned by the rightmost expression (See this for more details). First printf(“Hello”) executes and prints “Hello”, the printf(” All Geeks “) executes and prints ” All Geeks “. This printf statement returns 11 which is assigned to i. Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above


My Personal Notes arrow_drop_up
Last Updated : 21 Oct, 2022
Like Article
Save Article
Similar Reads