# Output of C programs | Set 32

Predict the output of the following C programs.

1. What will be the output of following program?
Input:

`1 3`

 `#include ` `int` `main() ` `{ ` `    ``int` `a, b; ` `    ``if``(``scanf``(``"%d%d"``, &a, &b)==2) ` `        ``printf``(``"true"``); ` `    ``else` `        ``printf``(``"false"``); ` `    ``return` `0; ` `} `

Output:

```True
```

Explanation: Scanf function returns integer value as its return type is integer. In the above question, if you will enter two integer values, then it will return 2. It means “if condition” becomes true, otherwise “if condition” becomes false.

2. What will be the output of following program?:

 `#include ` `int` `main() ` `{ ` `    ``int` `a=0; ` `    ``a=a++ + a++ - a++ + ++a; ` `    ``printf``(``"%d\n"``, a); ` `    ``return` `0; ` `} `

Output:

`3`

Explanation: Prefix and postfix increment/decrement operator associativity is from Right to Left. So, in the above question it start executing from right side i.e. (++a).

```In the first step
A = (a++) + (a++)-(a++) + (1)
In the second step
A = (a++) + (a++)-(1) + (1)
In the third step
A = (a++) + (2)-(1) + (1)
In the fourth step
A = (3) + (2)-(1) + (1)
Therefore final value of A is 3.```

3. What will be the output of following program?

 `#include ` `int` `ar[] = {18, 23, 45, 56, 4, 6, 45}; ` `int` `main() ` `{ ` `    ``int` `i, x; ` `    ``x = (``sizeof``(ar)/``sizeof``(ar)); ` `     `  `    ``for` `(i=-1; i<=(x-2); i++) ` `        ``printf``(``"%d, "``, ar[i+1]); ` `} `

Output:

`18, 23, 45, 56, 4, 6, 45,`

Explanation: Sizeof and equal operator associativity is from right to left. Sizeof operator either returns the byte size of single element or container element sizes. Therefore, sizeof(ar) will return 4 byte as we pass single element of integer type in sizeof operator as integer take 4 byte and sizeof(ar) will return total size of array container i.e. 4*7=28.

4. What will be the output of following program?

 `#include ` `int` `count; ` `void` `display(); ` `int` `main() ` `{ ` `    ``count = 1; ` `    ``printf``(``"Value of count is %d, "``, count); ` `    ``display(); ` `} ` `void` `display() ` `{ ` `      ``extern` `int` `count; ` `      ``printf``(``"\nValue of count is %d"``, count); ` `} `

Output:

```Value of count is 1
Value of count is 1```

Explanation: As in this question, count is an global variable in the program. We assign 1 to count variable in main function which will further passes to display function. “Extern int count” is a way to define global variable in any function.
5. What will be the output of following program?
Input:

```1
c```

 `#include ` `int` `main() ` `{ ` `    ``int` `flag = 0, flag1 = 0, n; ` `    ``char` `s; ` `    ``flag = ``scanf``(``"%d"``, &n); ` `    ``flag1 = ``scanf``(``"%d"``, &s); ` `    ``printf``(``"Value of flag is %d"``, flag); ` `    ``printf``(``"\nValue of flag is %d"``, flag1); ` `    ``return` `0; ` `} `

Output:
Value of flag is 1
Value of flag is 0
Explanation: Scanf function will return integer value. In the above question, if it get executed successfully it will return 1 otherwise it will return 0. Therefore flag=scanf(“%d”, &n) will return 1 because it scan an integer value and flag=scanf(“%d”, &s) will return 0 because it fail to scan character value. And if you will not insert any value then it will return -1.

6. What will be the output of following program?

 `#include ` `union` `student ` `{ ` `    ``int` `y; ` `    ``char` `var2; ` `    ``char` `arr; ` `    ``char` `ch; ` `}; ` `int` `main() ` `{ ` `    ``union` `student st; ` `    ``printf``(``"%d"``, ``sizeof``(``union` `student)); ` `    ``return` `0; ` `} `

Output:

`136`

Explanation:Union has a property to store different data types in same memory location one at a time. It generate a maximum memory space container so that it stores the every data type value. As according to union property sizeof operator will return maximum memory allocation in union container (Maximum no. of bytes).

This article is contributed by Ashish Varshney. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.