Write any small program that will compile in "C" but not
in "C++"
Answers were Sorted based on User's Feedback
Answer / pulkit dave
void main()
{
int class=28;
printf("%d",class);
}
it works...
[class] :p
Is This Answer Correct ? | 18 Yes | 3 No |
Answer /
void main()
{
const var;
}
gives error in c++ but not in c....
Is This Answer Correct ? | 5 Yes | 0 No |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Is c# written in c++?
Write a program to find the Factorial of a number
Can you sort a set c++?
What are the various oops concepts in c++?
Live example for static function?
. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?
What is an operator in c++?
Why do we use the using declaration?
Is oops and c++ same?
Describe run-time type identification?
Why can’t you call invariants() as the first line of your constructor?
Explain method of creating object in C++ ?