Skip to content
Related Articles
Open in App
Not now

Related Articles

Output of C++ programs | Set 45

Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 29 Apr, 2022
Improve Article
Save Article
Like Article

Q.1 What Is The Output Of this program?
 

CPP




#include <iostream>
using namespace std;
int main()
{
    int a = b = c = 10;
    a = b = c = 50;
    printf("%d %d %d", a, b, c);
    return 0;
}


Option 
a) 50 50 50 
b) Three Garbage Value 
c) 10 10 10 
d) Compile Time Error 
 

Ans: d

Explanation : In this program, b and c are not declared and we can not directly assign the value to them so “Compilation Time” error occurred.
Q.2 What Is The Output Of this program? 
 

CPP




#include <iostream>
using namespace std;
int main()
{
    double x = 28;
    int k;
    k = (int)x % 5;
    k = k << 2;
    printf("hx=%x", k);
    return 0;
}


Option 
a) hx = a 
b) hx = 12 
c) hx = c 
d) hx= 13 
 

Ans: C

Explanation : In this code a double value modulus an integer value is given and further the result is left shifted 2 bits and printed in hexa-decimal form.
Q.3 What Is The Output Of this program? 
 

CPP




#include <iostream>
#define square(x) x* x
#define square1(x) (x) * (x)
using namespace std;
int main()
{
    printf("%d, ", square(10 + 2));
    printf("%d", square1(10 + 2));
    return 0;
}


Option 
a) 144, 32 
b) 32, 144 
c) 100, 12 
d) 12, 144 
 

Ans: B

Explanation : In this program, #define macro used to replace value and calculated them like this: 
 

10 + 2 * 10 + 2 = 32 
or (10+2)*(10+2) = 144 

Q.4 What Is The Output Of this program? 
 

CPP




#include <iostream>
using namespace std;
int main()
{
    int i;
    i = 0x18 + 0110 + 11;
    printf("p= %d", i);
    return 0;
}


Option 
a) p= 101 
b) p= 107 
c) p= 40 
d) Error 
 

Ans: B

Explanation : In this program 0x is hexa-decimal notation and 0 is octal, convert these value in decimal and add them.
Q.5 What Is The Output Of this program? 
 

CPP




#include <iostream>
using namespace std;
int main()
{
    char* a = "INFO";
    a++;
    printf("%s", a);
    return 0;
}


Option 
a) Error 
b) INFO 
c) NFO 
d) None of these 
 

Ans: C

Explanation : In this program, *a is hard core string that contain a base address of string. When we increment the address, it points to next value of the string.
This article is contributed by Gyayak jain . If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@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
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!