Introduction To C Plus Plus - Study Mode

[#111] What happens if the following program is executed in C and C++? #include <stdio.h>
int main(void)
{
int new = 5
printf("%d", new)
}
Correct Answer

(D) Error in C++ and successful execution in C

[#112] What will be the output of the following C++ code? #include <iostream>
using namespace std
class Test
{
static int x
public:
Test() { x++
}
static int getX() {return x
}
}
int Test::x = 0
int main()
{
cout << Test::getX() << " "
Test t[5]
cout << Test::getX()
}
Correct Answer

(C) 0 5

[#113] What happens if the following program is executed in C and C++? #include<stdio.h>
int main()
{
foo()
}
int foo()
{
printf("Hello")
return 0
}
Correct Answer

(C) Error in C++ but Warning in C

[#114] What will be the output of the following C++ code? #include<iostream>
using namespace std
int x = 1
int main()
{
int x = 2
{
int x = 3
cout << ::x << endl
}
return 0
}
Correct Answer

(A) 1

[#115] What happens if we run the following code in both C and C++? #include<stdio.h>
struct STRUCT
{
int a
int func()
{
printf("HELLO THIS IS STRUCTURE
")
}
}
int main()
{
struct STRUCT s
s.func()
return 0
}
Correct Answer

(B) The program gives an error in case of C but runs perfectly in case of C++