main()

{

int *j;

{

int i=10;

j=&i;

}

printf("%d",*j);

}

Answers were Sorted based on User's Feedback



main() { int *j; { int i=10; j=&i; } pri..

Answer / susie

Answer :

10

Explanation:

The variable i is a block level variable and the visibility
is inside that block only. But the lifetime of i is lifetime
of the function so it lives upto the exit of main function.
Since the i is still allocated space, *j prints the value
stored in i since j points i.

Is This Answer Correct ?    78 Yes 5 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / vishu

the answer is that
int i varibale is part of int*j block code ,but outside the
block of code i variable also show their existanse.if we
write a code after the int*j block of code .
int*h
{
h=&i
}
printf("%d",*h);

}

Is This Answer Correct ?    11 Yes 3 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / anand

j=10

Is This Answer Correct ?    12 Yes 4 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / bipin chandra sai.s

actually j has beeen assigned the addresss of i so the ans
will be the value present in the address location 10

Is This Answer Correct ?    7 Yes 1 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / jerome.s,final year eee,adhipa

There i-is initialised by 10.
and j-also initialised by address of i.
so *j is the value in the address of j.
therefore,
*j=i=10.
OUTPUT:
10

Is This Answer Correct ?    7 Yes 1 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / sivakrishna

j=10

Is This Answer Correct ?    7 Yes 2 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / ashish p

The answer is undefined.
int *j;
{ //prolog
int i=10;
j = &i;
}//epilog

in the above code , at the prolog level the variables are
pushed into a un-named function space on the stack. Whereas
at epilog level the variable i dies.
J contains address of valid memory location but invalid
contents. Since i's memory is release back, any other
program can claim it and over-ride the contenets. Unless
then if we try to print the content using J it will give us
the value 10.
Which is not recommended it is something like returning
reference to the local variable in a function.

Is This Answer Correct ?    1 Yes 1 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / govind verma

i think ans will be 10 because here is the concept of dagling pointer......

Is This Answer Correct ?    0 Yes 0 No

main() { int *j; { int i=10; j=&i; } pri..

Answer / hameennaveen

error

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C Code Interview Questions

main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }

1 Answers  


All the combinations of prime numbers whose sum gives 32

1 Answers   HHH,


main() { int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } }

2 Answers  


Cau u say the output....?

1 Answers  


main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }

1 Answers   Zoho,






PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1 Answers  


#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }

3 Answers  


main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }

2 Answers  


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

0 Answers  


What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  


void main() { static int i=5; if(--i){ main(); printf("%d ",i); } }

1 Answers  


#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

2 Answers   CNSI,


Categories