Open In App

Output of C programs | Set 55

Last Updated : 13 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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. 1865
2. runtime error
3. Syntax error
4. 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. 5
2. 1
3. incompatible type declaration
4. -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. GEEKS
2. run-time error
3. GEEKS infinitely
4. 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. 54
2. 44
3. 45
4. 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. 100
2. 110
3. 105
4. 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=0
2. No output
3. compile time
4. 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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads