Write any small program that will compile in "C" but not
in "C++"

Answers were Sorted based on User's Feedback



Write any small program that will compile in "C" but not in "C++"..

Answer / pulkit dave

void main()
{
int class=28;
printf("%d",class);
}


it works...

[class] :p

Is This Answer Correct ?    17 Yes 3 No

Write any small program that will compile in "C" but not in "C++"..

Answer /

void main()
{
const var;
}

gives error in c++ but not in c....

Is This Answer Correct ?    5 Yes 0 No

Write any small program that will compile in "C" but not in "C++"..

Answer / murali

hi(){ }

g++ -x c++ -c test1.cpp
test1.cpp:1: ISO C++ forbids declaration of `hi' with no
type

gcc -x c -c test1.cpp
Here the default return type is int.

Is This Answer Correct ?    6 Yes 2 No

Write any small program that will compile in "C" but not in "C++"..

Answer / nitesh

ans 3 and 4 are incorrect in my opinion.

xyz()
{
printf("very good");
}
can be compiled by including the header file "Stdio.h"

Is This Answer Correct ?    6 Yes 4 No

Write any small program that will compile in "C" but not in "C++"..

Answer / sauarv

answer no.. 6 is the most correct solution

as the class is a keyword in c++

but for answer 9 ,,ur prediction is correct that it will give error in c++ ,,although ur reason is not right

printf n csanf are not c specific

Is This Answer Correct ?    1 Yes 0 No

Write any small program that will compile in "C" but not in "C++"..

Answer / uma sankar pradhan

xyz()
{
printf("very good");
}

the above code will compile in 'c'
but in 'c++' it will give compilation error

Is This Answer Correct ?    5 Yes 6 No

Write any small program that will compile in "C" but not in "C++"..

Answer / karunesh

int GetNum()
{

printf("this will compile under c but not in c++");

}

you will get a error under g++ funtion should return int
while in c i will work with warning.

Is This Answer Correct ?    0 Yes 3 No

Write any small program that will compile in "C" but not in "C++"..

Answer / balasubramani

main()
{
char a;
printf("string:");
scanf("%s",a);
getch();
}

this is correct if v compile in c
but it results in error when u code xactly the same in cpp
bcoz cpp needs cout n cin instead of printf n scanf :D lol

Is This Answer Correct ?    2 Yes 6 No

Write any small program that will compile in "C" but not in "C++"..

Answer / tareq

<code>
int class;
</code>

$gcc a.c -c; echo $?
0

$g++ a.c -c; echo $?
a.c:1: error: expected identifier before ';' token
a.c:1: error: multiple types in one declaration
a.c:1: error: declaration does not declare anything
1

Is This Answer Correct ?    1 Yes 6 No

Write any small program that will compile in "C" but not in "C++"..

Answer / aravind

xyz()
{
printf("very good");
}

this is correct and if u add getch();
in main then there is no chance of compilation in CPP for sure

Is This Answer Correct ?    3 Yes 11 No

Post New Answer

More C++ General Interview Questions

Is rust better than c++?

0 Answers  


Does c++ have string data type?

0 Answers  


List the issue that the auto_ptr object handles?

0 Answers  


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

0 Answers  


class Foo { public: Foo(int i) { } }; class Bar : virtual Foo { public: Bar() { } }; Bar b; Referring to the above code, when the object 'b' is defined, a compiler error will occur. What action fixes the compiler error? a) Adding a virtual destructor to the class Bar b) Adding a constructor to Bar which takes an int parameter c) Adding "Foo()" to the Bar constructor d) Adding a copy constructor to the class Foo e) Adding "Foo(0)" to the Bar::Bar initializer list

2 Answers   Quark,






Incase of a function declaration, what is extern means?

0 Answers  


what is scupper?

0 Answers  


If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2.

1 Answers  


How can you force instantiation of a template?

1 Answers   ABC, Amazon,


What is the use of pointer in c++ with example?

0 Answers  


How do you print for example the integers 3,2,1,5,4 in a binary tree within the console in format where it looks like an actual binary tree?

0 Answers  


If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

0 Answers  


Categories