Output of C programs | Set 55 - GeeksforGeeks

06 Sep, 2017
1. What will be the output of the following program?
#include <stdio.h>int main(){    int a = 03489;    printf("%d", a);    return (0);}
Options:1. 18652. runtime error3. Syntax error4. 0
 The answer is option(3).
Explanation:
Any integral value prefix with 0 acts as octal number but the allowed digits is 0 to 7. But here 8 and 9 is there, which result in syntax error.
2. What will be the output of the following program?
#include <stdio.h>int main(){    char c;    int i;    c = 'B';    i = c - 'A';    printf("%d", i);    return (0);}
Options:1. 52. 13. incompatible type declaration4. -5
The answer is option(2).
Explanation : Here i declared as integer. So, it will manipulate the ASCII values.Since the ASCII value of B is 66 and ASCII value of A is 65. Therefore i = c-‘A’ = 1.
3. What will be the output of the following program?
#include <stdio.h>int main(){    printf("GEEKS");    main();    return (0);}
Options:1. GEEKS2. run-time error3. GEEKS infinitely4. compile time error
 The answer is option(3).
Explanation:Because main() function is calling itself repeatedly.
4. what will be the output of the following program?
#include <stdio.h>int main(){    int n, i = 5;    n = - - i--;    printf("%d%d", n, i);    return (0);}
Options:1. 542. 443. 454. 55
 The answer is option(1).
Explanation:Here minus*minus acts as plus before the i in the statement n=- -i–.Reference: https://www.geeksforgeeks.org/unary-operators-cc/
5. what will be the output of the following program?
#include <stdio.h>int main(){    int a = 10;    printf("%d", a++ * a++);    return (0);}
Options:1. 1002. 1103. 1054. No output
 The answer is option(2).
Explanation:Here a++ is post increment. so when it gets a++ then for the value of a changed to 11 in a buffer but still a=10. when it gets called one more time, a will be 11. so it will be 11*10=110.
6. what will be the output of the following program?
#include <stdio.h>int main(){    int a = 20, b = 8, c;    c = a != 5 || b == 4;    printf("c=%d", c);    return (0);}
Options:1. c=02. No output3. compile time4. c=1
 The answer is option(4).
Explanation:In the above program logical OR operator takes place.Here a!=5 is true which return 1 and rest of the code will not going to be execute because in logical OR if the first condition is true then the rest code will be not execute.
This article is contributed by Bishal Kumar Dubey. 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.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
C-Output
Misc
Misc
Misc
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Advantages and Disadvantages of OOP
Challenges in Internet of things (IoT)
Consensus Algorithms in Blockchain
Election algorithm and distributed processing
Transmission Impairment in Data Communication
Lex Program to count number of words
Bubble Sort algorithm using JavaScript
How to insert elements in C++ STL List ?
Characteristics of Internet of Things
Properties of Fourier Transform