Will this C++ program execute or not?

Submitted by: Administrator
void main()
{
char *cptr = 0?2000;
long *lptr = 0?2000;
cptr++;
lptr++;
printf(" %x %x", cptr, lptr);
}Will it execute or not?


Answer1
For Q2: As above, won't compile because main must return int. Also, 0x2000 cannot be implicitly converted to a pointer (I assume you meant 0x2000 and not 0?2000.)

Answer2
Not Excute.
Compile with VC7 results following errors:
error C2440: ‘initializing' : cannot convert from ‘int' to ‘char *'
error C2440: ‘initializing' : cannot convert from ‘int' to ‘long *'


Not Excute if it is C++, but Excute in C.
The printout:
2001 2004

Answer3
In C++
[$]> g++ point.c
point.c: In function `int main()':
point.c:4: error: invalid conversion from `int' to `char*'
point.c:5: error: invalid conversion from `int' to `long int*'

in C
------------
[$] etc > gcc point.c
point.c: In function `main':
point.c:4: warning: initialization makes pointer from integer without a cast
point.c:5: warning: initialization makes pointer from integer without a cast
[$] etc > ./a.exe
2001 2004
Submitted by: Administrator

Read Online C++ Programming Job Interview Questions And Answers