Open In App

Output of C programs | Set 51

Improve
Improve
Like Article
Like
Save
Share
Report

1. What will be the output of the below program?




#include <stdio.h>
int main()
{
    printf("%d", printf("%d", printf("%d", printf("%s", "Welcome to geeksforgeeks"))));
    return (0);
}


Options:
1. Welcome to geeksforgeeks2531
2. Welcome to geeksforgeeks2421
3. Welcome to geeksforgeeks2124
4. Welcome to geeksforgeeks3125

The answer is option(2).

Explanation : As we all know that the printf function returns the numbers of character that is going to print and scanf function returns the number of input given.

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




#include <stdio.h>
int main()
{
    int x = 30, y = 25, z = 20, w = 10;
    printf("%d ", x * y / z - w);
    printf("%d", x * y / (z - w));
    return (0);
}


Options:
1. 27 85
2. 82 27
3. 27 75
4. No output

 The output is option(3).

Explanation : In the above program, precedence takes the advantage. Therefore In the statement compiler first calculate x*y then / and after that subtraction.
Refer : https://www.geeksforgeeks.org/c-operator-precedence-associativity/

3. Guess the output?




#include <stdio.h>
int main()
{
    int a = 15, b;
    b = (a++) + (a++);
    a = (b++) + (b++);
    printf("a=%d b=%d", a, b);
    return (0);
}


Options:
1. a=63 b=33
2. a=33 b=63
3. a=66 b=33
4. a=33 b=33

The answer is option(1).

Explanation:Here,

a = 15 and b = (a++)+(a++) i.e. b = 15+16 = 31 and a =3 2.
Now a = (b++) + (b++) = 31 + 32 = 63 and b = 33.
Therefore the result is a = 63 and b = 33.

Refer: https://www.geeksforgeeks.org/operators-in-c-set-1-arithmetic-operators/

4. What will be the output?




#include <stdio.h>
int main()
{
    main();
    return (0);
}


Options:
1. compile time error
2. abnormal termination
3. run time error
4. No output

The answer is option(1).

Explanation:Here stack overflow occurs that’s result in run-time error.
Refer: https://www.geeksforgeeks.org/print-geeksforgeeks-empty-main-c/

5. What will be the output of following program?




#include <stdio.h>
int main()
{
    int c = 4;
    c = c++ + ~++c;
    printf("%d", c);
    return (0);
}


Options:
1. 3
2. -3
3. 31
4. compile time error

 The answer is option(2).

Explanation:Because here c++ is post increment and so it takes value as 4 then it will increment. ++c is pre-increment so it increment first and value 6 is assigned to c, .~ means -6-1=-7 then c=(4-7)=-3.



Last Updated : 24 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads