Open In App

Output of C++ programs | Set 45

Improve
Improve
Like Article
Like
Save
Share
Report

Q.1 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) 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()
{
    int i;
    i = 0x18 + 0110 + 11;
    printf("p= %d", i);
    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>
using namespace std;
int main()
{
    char* a = "INFO";
    a++;
    printf("%s", a);
    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





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.

 



Last Updated : 29 Apr, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads