Re: C- Tricky Question & answers With explanation C- Tricky Question & answers
1) In the following pgm add a stmt in the function fun such that the address of
'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
} Answer:
*k = &a Explanation:
The argument of the function is a pointer to a pointer.
2) What are the following notations of defining functions known as?
i. int abc(int a,float b)
{
/* some code */
}
ii. int abc(a,b)
int a; float b;
{
/* some code*/
} Answer:
i. ANSI C notation
ii. Kernighan & Ritche notation
3) main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
} Answer:
300 Explanation:
The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.
__________________
J.Vijayanand |