PDA

View Full Version : C aptitude questions



neetu21
January 19th, 2006, 09:07 PM
hi friends
i am sending some questions on C which are useful for placement point of view. See the attachment. Besides these, those who are preparing, can refer following books:

1) Test your C skills by Yashwant Kanitkar
2) Test your C++ skills (author same as above)
3) C++ Faq Lite by Marshall Cline

devdahiya
January 19th, 2006, 09:14 PM
It is a nice feeling to see young people with such a positive and helping attitudes. Keep it up Neetu! God bless !

vijay
January 20th, 2006, 12:05 PM
hi friends
i am sending some questions on C which are useful for placement point of view. See the attachment. Besides these, those who are preparing, can refer following books:

1) Test your C skills by Yashwant Kanitkar
2) Test your C++ skills (author same as above)
3) C++ Faq Lite by Marshall Cline


Hi Neetu,

Are you a C programmer. I like programming in C/C++. I have all the books you mentioned above besides these some other books too.

Ok i am posting a program problem . Anybody try to solve it :

#include<stdio.h>

void change()
{
/*Write something in this function so that the output of printf in main
function should give 5 . You can not change the main function */
}


int main()
{
int i=5;
change();
i=10;
printf("%d",i);
return 0;
}

tomar.iitr
January 23rd, 2006, 02:52 PM
there can be more way , i found only 2 ..
1.
#include <stdio.h>
void change()
{
#define printf(x,q) printf(x,5)
}
int main ()
{
int i=5;
change();
i=10;
printf("%d",i);
return 0;

}

2.
#include <stdio.h>
void change()
{
printf("%d",5)
exit(0);
}
int main ()
{
int i=5;
change();
i=10;
printf("%d",i);
return 0;

}

vijay
January 23rd, 2006, 03:23 PM
there can be more way , i found only 2 ..
1.
#include <stdio.h>
void change()
{
#define printf(x,q) printf(x,5)
}
int main ()
{
int i=5;
change();
i=10;
printf("%d",i);
return 0;

}

2.
#include <stdio.h>
void change()
{
printf("%d",5)
exit(0);
}
int main ()
{
int i=5;
change();
i=10;
printf("%d",i);
return 0;

}

Hi

In first answer, is that a good programming practice to include #define within a function i don't think so. How many times you use it in your programming ?

In second answer, curser didn't go to the printf in main() as program terminated before that.

Well try