A
aarklon
1) I have seen programs like this:-
#include<stdlib.h>
#include<stdio.h>
void f(j)
{ printf("\n j = %d",j); }
void fun(i){ void (*p)(int); p = f; p(100 + i); (p)(100 + i); }
int main(void)
{
void (*ptr)(int);
ptr = fun;
(*ptr)(222);
ptr(333);
puts("\nEND OF THE PROGRAM");
return(EXIT_SUCCESS);
}
does this mean that if we are defining a function without
explicitly specifying the type of the parameter,
will it default to int (signed or unsigned)???
2) how this program works..???
#include<stdlib.h>
#include<stdio.h>
char fun()
{
static i = 3;
int main = 10;
return
printf("%d\n",i-- > 0 ?i && fun():main);
}
int main(void)
{
fun();
puts("");
return(EXIT_SUCCESS);
}
o/p is given as :- 0 1 1
is ternary operator a sequence point...????
for the first time when the function is called
how will be i && fun() evaluated....???
assuming ternary operator is not sequence point
i && fun() will evaluate to 3 && fun()
is n't it then what value will fun() evaluate to...????
3) is there any concept of default return value for a function
returning int...???
suppose i am having a fn such as this
int myfun()
{
}
and i am calling it in main as
#include<stdio.h> main(){printf("%d",myfun())}
what value will it print by default...???
4) why the following program prints o/p correctly as far as my
understanding
goes this program returns address of local variable is n't
it...???
int* f()
{
int a = 12;
return &a;
}
int* fun()
{
int *b = f();
return b;
}
int main(void)
{
printf("\nfun = %d",*(fun()));
puts("");
return(EXIT_SUCCESS);
}
#include<stdlib.h>
#include<stdio.h>
void f(j)
{ printf("\n j = %d",j); }
void fun(i){ void (*p)(int); p = f; p(100 + i); (p)(100 + i); }
int main(void)
{
void (*ptr)(int);
ptr = fun;
(*ptr)(222);
ptr(333);
puts("\nEND OF THE PROGRAM");
return(EXIT_SUCCESS);
}
does this mean that if we are defining a function without
explicitly specifying the type of the parameter,
will it default to int (signed or unsigned)???
2) how this program works..???
#include<stdlib.h>
#include<stdio.h>
char fun()
{
static i = 3;
int main = 10;
return
printf("%d\n",i-- > 0 ?i && fun():main);
}
int main(void)
{
fun();
puts("");
return(EXIT_SUCCESS);
}
o/p is given as :- 0 1 1
is ternary operator a sequence point...????
for the first time when the function is called
how will be i && fun() evaluated....???
assuming ternary operator is not sequence point
i && fun() will evaluate to 3 && fun()
is n't it then what value will fun() evaluate to...????
3) is there any concept of default return value for a function
returning int...???
suppose i am having a fn such as this
int myfun()
{
}
and i am calling it in main as
#include<stdio.h> main(){printf("%d",myfun())}
what value will it print by default...???
4) why the following program prints o/p correctly as far as my
understanding
goes this program returns address of local variable is n't
it...???
int* f()
{
int a = 12;
return &a;
}
int* fun()
{
int *b = f();
return b;
}
int main(void)
{
printf("\nfun = %d",*(fun()));
puts("");
return(EXIT_SUCCESS);
}