Output of C programs | Set 54

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

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
#define GEEKS 100
int main()
{
#define GEEKS 100
    printf("%d", GEEKS);
    return (0);
}
Output:
- 100

chevron_right


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

The answer is option(1).

Explanation : As GEEKS macro replace the GEEKS with 100 token.
Refer : https://www.geeksforgeeks.org/interesting-facts-preprocessors-c/



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

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
#include <string.h>
int main()
{
    printf("%d%d", sizeof("GEEKSFORGEEKS"), strlen("GEEKSFORGEEKS"));
    return (0);
}

chevron_right


Options:
1. 1314
2. 1134
3. 1413
4. 3114

 The output is option(3).

Explanation : As we all know that sizeof() function return the length without counting \0(null) character but strlen() function return the length of string with \0 character.
Refer : https://www.geeksforgeeks.org/difference-strlen-sizeof-string-c-reviewed/

3. Guess the output?

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Options:
1. -4
2. compile error
3. runtime error
4. 4

The answer is option(4).

Explanation : When we use unary minus(-) operator twice then the compiler treats as plus.

4. What will be the output?

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main()
{
    char c[] = "GFG";
    int i;
    for (i = 0; c[i]; i++) {
        printf("%c%c%c%c", c[i], *(c + i), *(i + c), i);
    }
    return (0);
}

chevron_right


Options:
1. compile time error
2. GGGGFFFFGGGG
3. GFG
4. No output

 The answer is option(2).

Explanation : Here all c[i], *(c+i), *(i+c), i represent the same thing. In the first loop, all four specifiers points to G that’s why in the fist loop it prints GGGG and in the 2nd loop FFFF and at last in the 3rd loop GGGG.

5. What will be the output of following program?

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Options:
1. 4555
2. 5545
3. 5545
4. 5554

 The answer is option(1).

Explanation : Any integer number which is prefix with 0 indicates as Octal number. Now after conversion of 055 into decimal number we have 45 and b is 55. Therefore the answer is 4555.

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.



My Personal Notes arrow_drop_up



Article Tags :

5


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.