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

can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

0 Answers   TCS,


Design an implement of the inputs functions for event mode

0 Answers   Wipro,


main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }

2 Answers   HP,


main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }

1 Answers  


main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }

1 Answers  






Write a routine to implement the polymarker function

0 Answers   TCS,


main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above

3 Answers   HCL,


how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!

8 Answers   GATE,


Write a routine that prints out a 2-D array in spiral order

3 Answers   Microsoft,


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

3 Answers  


void main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } }

1 Answers  


write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"

2 Answers  


Categories