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

Why is c++ considered difficult?

0 Answers  


What do you know about near, far and huge pointer?

0 Answers  


Any one help me plzzzz..... i have an assignment...... that is ______*********_______ Write a program that takes an equation as a string and does the following: Solve 8 parts to achieve 100% 1 - 5 are compulsory. Input: 2x^2+3x+4=0 1) read a quadratic equation 2) print its coefficients (coefficients range is 0 to 9) 3) print the solution of the equation 4) tackle imaginary solution e.g. ( (2+3i), (2-3i) ) 5) allow spaces within the input 6) after solving one equation; ask for an other, terminate on empty line. * 7) tackle negative values as well * 8) tackle more than one values of same exponent (e.g. 2x^2 + 3x^2 + 4x + 3 = 0)* 9) use strtok * 10) print the solution in fractions e.g. 1.5 should be printed as (1)1/2 * 11) coefficient can be greater than 9** 12) values on both sides of the ‘=’ sign** 13) plot the graph of the polynomial** 14) use a compiler other than Borland** 15) submit before May 25, 2009 11:59 PM ** _______******________ plz send me c++ code at sweety.alvi@gmail.com

1 Answers  


Why iomanip is used in c++?

0 Answers  


Can turbo c++ run c program?

0 Answers  






What is optimization in c++? when using volatile.optimization is not possible..what does this mean?

1 Answers  


State two differences between C and C++.

0 Answers   Hexaware,


what are the decision making statements in C++? Explain if statement with an example?

0 Answers  


What is a template in c++?

0 Answers  


What is the real purpose of class – to export data?

0 Answers  


What is static function? Explain with an example

0 Answers  


What size is allocated to the union variable?

0 Answers  


Categories