C aptitude questions

Status
Not open for further replies.

neetu21

New member
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
 
Last edited:
Positive attitude

It is a nice feeling to see young people with such a positive and helping attitudes. Keep it up Neetu! God bless !
 
neetusharawat said:
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;
}


 
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;

}
 
tomar_iitr said:
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






 
Status
Not open for further replies.
Back
Top