Output of C programs | Set 48
1. What is the output of following program?
(D) Garbage value
Answer : (C)
Explanation : The macro function square(x)(x*x) calculates the square of the given number.
Initially int y = 1; In the next step x = square(y+1); x = y+1 * y+1; Here square(x) is replaced x*x . x = 1+1 * 1+1; x = 1 + 1 + 1; x = 3;
2. What is the output of following program?
The code given below is executed from command Line.
Input given by the user: myfile 2 4 6
(A) It will reflect a garbage value.
(D) myfile 12
Answer : (B) Error
Explanation : Error because argv, argv and argv areof string type and we cannot perform arithmetic operations without converting the string to integer type.
3. What is the output of following program?
(D) Garbage value
Answer :(B) 144
Explanation : Since the input is beyond the range of unsigned char it will reflect the input’s cyclic value.
4.What is the output of following program?
(D) A garbage value.
Explanation:The loop will run 5 times. Now, we provide the input as ‘X’. Which is scanned as ‘input’.
printf("%c", input); The above line prints 'X'
Now the ungetc(input, stdin) statement pushes the character’X’ back into input stream.
For the next run of the loop.
The scanf statement gets the input from “stdin” because of “ungetc” function used previously. Now the printf statement will print ‘X’ Since input= ‘X’ and ungetc(input, stdin) pushes ‘X’ back to the input stream and the same process will take place for the remaining iterations.
5. What is the output of following program?
Explanation : printf() allows variable number of arguments. Since there is no format specifier, second parameter is ignored with warning.
This article is contributed by Siddharth Pandey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Please Login to comment...