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;
}
#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++
Answer: Option B
Related Questions on Introduction to C plus plus
What does the 'cin' object in C++ represent?
A. File output stream
B. File input stream
C. Standard output stream
D. Standard input stream

Join The Discussion