ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
Write any small program that will compile in "C" but not 
in "C++"
 Question Submitted By :: Paku_4u
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Write any small program that will compile in "C" but not in "C++"
Answer
# 1
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 ?    1 Yes 1 No
Murali
 
  Re: Write any small program that will compile in "C" but not in "C++"
Answer
# 2
<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 ?    0 Yes 1 No
Tareq
 
 
 
  Re: Write any small program that will compile in "C" but not in "C++"
Answer
# 3
xyz()
{
printf("very good");
}

the above code will compile in 'c'
but in 'c++' it will give compilation error
 
Is This Answer Correct ?    0 Yes 1 No
Uma Sankar Pradhan
 
  Re: Write any small program that will compile in "C" but not in "C++"
Answer
# 4
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 ?    1 Yes 1 No
Aravind
 
  Re: Write any small program that will compile in "C" but not in "C++"
Answer
# 5
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 ?    0 Yes 0 No
Nitesh
 
  Re: Write any small program that will compile in "C" but not in "C++"
Answer
# 6
void main()
{
   int class=28;
   printf("%d",class);
}


it works... 

[class] :p
 
Is This Answer Correct ?    1 Yes 0 No
Pulkit Dave
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
int f() { int I = 12; int &r = I; r += r / 4; int *p = &r; *p += r; return I; } Referring to the sample code above, what is the return value of the function "f()"? a) 12 b) 15 c) 24 d) 17 e) 30 Quark2
write program for palindrome  3
How is an Abstract Base Class(ABC) related to an "Abstract Data Type" (ADT)  2
Difference between static global and global? Symphony8
Can inline functions have a recursion? Give the reason?  1
What is Pure Virtual Function? Why and when it is used ? Lucent4
What is the Diffrence between a "assignment operator" and a "copy constructor"? Wipro2
whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; Huawei4
how to swap two strings without using any third variable ?  3
Can we declare destructor as static? Explain?  2
wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster  8
What are the differences between a struct and a class in C++? Wipro4
How long does this loop run: for(int x=0; x=3; x++) a) Never b) Three times c) Forever Quark9
What are advantages of C++ when comparing with C? HP3
Difference between delete and delete[]? TCS3
write the prime no program in c++?  3
What is the use of static functions? Symphony6
How do you link a C++ program to C functions?  2
What is the output of: String a1 = "Hello"; String a2 = "world!"; String* s1 = &a2; String& s2 = a1; s1 = &a1; s2 = a2; std::cout << *s1 << " " << s2 << std::endl; Lehman-Brothers4
Difference between Top down and bottom up approaches for a given project ? HP1
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com