Meh.
Most of the problems either depend on the platform, use conio.h, or use non-standard extensions (typeless main(), void main()).
I imagine they were written using Borland's compiler.
Some of the questions don't even make sense. "What is the output of the following code if array name starts with 65486"? What's that supposed to mean?
Nothing really challenging (I'm pretty sure I could find some of these in production code), but okay if you're a beginner, I guess (except for the standard violations, that is).
not really: 22.what is the error if not specify the output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
f(a,b)
int a,b;
{
return (a=(a==b));
}
main()
{
int process(),f();
clrscr();
printf("the value of process :%d\n",process(f,7,4));
getch();
}
process(hai,val1,val2)
int (*hai)();
int val1,val2;
{
return ((*hai)(val1,val2));
}
NO, you can't learn from them:
1st challenge: 1. what is the output? Definitely the output is not what you think! so think more.
1 2 3 4 5 6 7 8
main()
{
int i = 300;
char *ptr = &i;
*++ptr = 2;
printf("%d",i);
getch();
}
That depends on the computer you are working on, not on C ( nor C++ )
All the challenges (as I already mentioned) are in C written in a way which is incompatible with C++
And as helios already said:
Some of the questions don't even make sense. "What is the output of the following code if array name starts with 65486"? What's that supposed to mean?
Nonstandard code fragments, poor programming practices, ancient and outdated syntax. Better off not learning from this since what you learn will be wrong.
Whatever you said is correct except for the below one
"Whatever I said"? What do you mean? It's pretty clear what I said.
And no, it's not correct. The question says "... if the array name starts with 65486". Why would you interpret "name" as meaning anything other than "name", such as "address"?
It doesn't make sense for an identifier to start with a digit; and if it does mean "address", then it's improperly redacted, which makes the question invalid, anyway. You can't just go around writing questions that don't make sense and hope your readers will guess what was going through your mind when you made that written disaster.
I don't even want to think what that guy's code must be like.
Is it even possible? The function doesn't know the variables exist since it's not in the functions scope plus nothing is passed. How would you go about that? :$
void f(){
int *i=(int*)(unsigned(&i)+92),*j=(int*)(unsigned(&j)+92);
std::cout <<*i<<","<<*j<<std::endl;
return;
}
Unsurprisingly, this only compiles and runs correctly on VC++. It breaks if I so much as change the build options.
I feel dirty. I mean, the time I managed to change what a reference points to, that was bad enough. But accessing something in a different stack frame? It goes beyond ugly.