C++ MCQ’s

C++ MCQ’s Home Page

C++ Basic 1
C++ Basic 2
C++ Basic 3
C++ Basic 4
C++ Basic 5
C++ OOPs Concepts 1
C++ OOPs Concepts 2
C++ OOPs Concepts 3
C++ OOPs Concepts 4
C++ OOPs Concepts 5

 

Cpp Language MCQ’S | OOPs Concepts Set 3

21.
Which of the following is correct?

a) struct tag is required in both C and C++ while declaring an object of the structure
b) struct is not required in C but required in C++ while declaring an object of the structure
c) struct is not required in C++ but required in C while declaring an object of the structure
d) struct tag is not required in both C and C++ while declaring an object of the structure

 

22.
Which of the following is correct?

a) struct cannot have member function in C but it can in C++
b) struct cannot have member function in C++ but it can in C
c) struct cannot have member function in both C and C++
d) struct can have member function in both C and C++

 

23.
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\n”);
}
};
int main()
{
struct STRUCT s;
s.func();
return 0;
}

a) The program runs fine and both prints output “HELLO THIS IS STRUCTURE”
b) The program gives an error in case of C but runs perfectly in case of C++
c) The program gives an error in case of C++ but runs perfectly in case of C
d) The program gives an error in case of both C and C++

 

24.
What happens if we run the following code in both C and C++?

#include<stdio.h>
struct STRUCT
{
int a = 5;
int func()
{
printf(“%d\n”, a);
}
};
int main()
{
struct STRUCT s;
s.func();
return 0;
}

a) The program runs fine and both prints output “HELLO THIS IS STRUCTURE”
b) The program gives an error in case of C but runs perfectly in case of C++
c) The program gives an error in case of C++ but runs perfectly in case of C
d) The program gives an error in case of both C and C++

 

25.
What happens if the following program is compiled in both C and C++?

#include<stdio.h>
struct STRUCT
{
int static a;
};
int main()
{
struct STRUCT s;
return 0;
}

a) The program runs fine and both prints output “HELLO THIS IS STRUCTURE”
b) The program gives an error in case of C but runs perfectly in case of C++
c) The program gives an error in case of C++ but runs perfectly in case of C
d) The program gives an error in case of both C and C++

 

Visitor Counter

0051009