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

Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

9 Answers   Microsoft,


main() { int y; scanf("%d",&y); // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year"); else printf("%d is not a leap year"); }

1 Answers  


main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }

2 Answers   Adobe, CSC,


what is brs test reply me email me kashifabbas514@gmail.com

0 Answers  


Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  






void main() { int c; c=printf("Hello world"); printf("\n%d",c); }

2 Answers  


x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);

2 Answers  


#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above

3 Answers   HCL,


given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit

8 Answers  


char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }

1 Answers  


#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }

2 Answers  


Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped

1 Answers   IBM,


Categories