Monday, July 9, 2007

Is there something we can do in C but not in C++?

I have a really funny answer

Declare variable names that are keywords in C++ but not C.


#include < stdio.h >
int main(void)
{
int old, new=3;
return 0;
}


This will compile in C, but not in C++!

14 comments:

Nirav said...

isn;t this a stupid question

praths said...

yep, sounds stupid but tricky though. Btw good reply

Anonymous said...

main()
{
const int a;
printf("%u",&a);
}
this cprogram will compile in turboc++
#include"iostream.h"
void main()
{
const int a;
cout<<&a;
}
this c++program will not compile in turboc++.

Anonymous said...

1)We can assign any type of pointer to void pointer without cast in c but not in c++.
2)
int main()
{
const int i;
}

will not give error in c but in c++.

Sumi said...

In c++ We must initlize the const variable .
You can try with const int a=0
Might will work

Sumi said...

In c++ We must initlize the const variable .
You can try with const int a=0
Might will work

Anonymous said...

The "designated initializer" syntax in ISO C99 is not available in C++.

http://stackoverflow.com/questions/1601201/c-struct-initialization-using-labels-it-works-but-how-documentation

http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Designated-Inits.html#Designated-Inits

Anonymous said...

Thanks for the info. It is very helpful.
RegardsEducational site
Get jobs info at Educational site

Anonymous said...

Hello! I simply wish to give you a big thumbs up for your excellent information
you have right here on this post. I'll be coming back to your site for more soon.

Here is my web-site - metabolic rate calculator

lee woo said...

There's a natural law of karma that vindictive people, who go out of their way to hurt others, will end up broke and alone. See the link below for more info.

#broke
www.mocsbar.com

soysoy said...

I definitely liked reading everything that is posted on your website. Where else could anyone get that type of facts in such a perfect way of writing?

www.triciajoy.com

soysoy said...

I definitely liked reading everything that is posted on your website. Where else could anyone get that type of facts in such a perfect way of writing?

www.triciajoy.com

Cindy Dy said...

Awesome there, Great work, keep it up. I love returning back to this site and reading the quality content you always have on offer.

Wendy
www.gofastek.com

lee woo said...

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.


ufgop.org
ufgop.org