Introduction To C Plus Plus - Study Mode
[#116] What happens if the following code is compiled on both C and C++? #include<stdio.h>
struct STRUCT
{
private:
int a
}
int main()
{
printf("%d
", (int)sizeof(struct STRUCT))
return 0
}
Correct Answer
(B) The program gives an error in case of C but runs perfectly in case of C++
[#117] What happens if the following program is executed in C and C++? #include <stdio.h>
int main(void)
{
const int j = 20
int *ptr = &j
printf("*ptr: %d
", *ptr)
return 0
}
Correct Answer
(D) Error in C++ but Warning in C
[#118] Which of the following C++ code will give error on compilation? ================code 1=================
#include <iostream>
using namespace std
int main(int argc, char const *argv[])
{
cout<<"Hello World"
return 0
}
========================================
================code 2=================
#include <iostream>
int main(int argc, char const *argv[])
{
std::cout<<"Hello World"
return 0
}
========================================
Correct Answer
(D) Neither code 1 nor code 2
[#119] What will be the output of the following C++ code? #include <stdio.h>
int main()
{
const int x
x = 10
printf("%d", x)
return 0
}
Correct Answer
(C) Error
[#120] In which part of the for loop termination condition is checked? for(I
II
III)
{IV}
Correct Answer
(B) II