Output of C++ programs | Set 44
Output In C++
Q.1 What is the output of below program?
a) Hello World 10
b) Hello World 11
c) Hello World 12
d) Hello World 0
ans :- b
Explanation : printf() returns count of characters successfully written on screen. In this program, printf() writes 10 character + 1 space total 11 so x is 11.
Q.2 What is the output of below program assuming that a character takes 1 byte and a pointer takes 8 bytes.
a) 12 10 8
b) 12 4 10
c) 12 8 10
d) 12 8 11
ans :- d
sizeof(a) : Character array size is 12 because in Hello World there are : 10 characters 1 space and 1 NULL.
sizeof(p) : 8 is pointer size of a pointer. Note that all pointer types take same size on a particular compiler.
strlen(a) : 11 is string length because length function not contain NULL character.
Q.3 What is the output of below program?
ans :- a
Explanation : This code compares ASCII values of A and C and return 1 because ASCII value of C greater than that of A.
Q.4 What is the output of below program?
a) 1, 2, 4, 5, 8, 9
b) 3, 6, 7
d) None of these
Explanation : This program basically prints all numbers (smaller than or equal to 10) that don’t have consecutive 1’s in binary representation. Please refer this article for details.
This article is contributed by Gyayak Jain . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.