int *p=20;
if u print like dis printf("%d",p);
o\p:- 20; how is it possible?
plz give me the explanation.

Answers were Sorted based on User's Feedback



int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / santhi perumal

We are assigning 20 to *p. Which means we are assigning the
address 20 to p. when you want to print the address of the
pointer variable we have to print just p not *p. if you want
to print the value stored in the particular address we need
to print like *p. in this case we are printing p so it will
give the address 20 to it.

Is This Answer Correct ?    31 Yes 5 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / valli

int *p=20;
means
int *p;
p=20;
so the address of p is 20
printf("%d",p);
it prints 20 because now the base address of p is 20
even if we print as
printf("%u",p);
the o/p will be 20

Is This Answer Correct ?    9 Yes 2 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / yogi

int *p=20;
This is like int *p;p=20;
printf("%d",p);It prints p properly as 20;
printf("%d",*p);It means deference the value at address 20,
which is invalid .

If we try to run,as address 20 is invalid and it tries to
fetch the value at address 20,signal 11 sent to that process
i.e it dumps core with segmentation fault

Is This Answer Correct ?    4 Yes 0 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / thunder

GIVES THE ERROR DURING COMPILATION.
*P means IT CAN STORE ADDRESS NOT ANY INTEGER VALUE.

Is This Answer Correct ?    6 Yes 5 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / saikishore

correct ans is
int *p ; // creating a pointer of integer type
*p=20; // we are creating memory for 20 and p is pointing to
it .
printf("%d",p); // prints p 's address

printf("%d",*p); // prints value pointed by p . i.e 20

wrong declarations
we
ERRORS 1.int *p=20;

Is This Answer Correct ?    4 Yes 3 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / udanesh

int *p=20 means
int *p;
p=20;
so when you print the value of p definitely you will get the output as 20 because the value of p is 20

Is This Answer Correct ?    1 Yes 0 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / sangram

p is a pointer and it holds address.
we are assigning 20 to p;it means pointer p points the value pointed by address 20.
so to show the value on address 20 you have give *p

Is This Answer Correct ?    0 Yes 0 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / deepak

/*int *p=20;
is same as*/
int *p;
p=20;
so p having address of an integer value;
so
printf("%d,%u",p,p);
will give you answer 20,20

Is This Answer Correct ?    0 Yes 1 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / sateeshbabu aluri

we are not printing the address of variable
it mens &p;
we are printing value of p.
so,P=20 will be the o/p.

Is This Answer Correct ?    3 Yes 5 No

int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give m..

Answer / ankit

it will show compiler error as we are trying to assign integer value to pointer variable.

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

What are static variables in c?

0 Answers  


write a c program for print your name .but,your name may be small letter mean print a capital letter or your name may be capital letter mean print a small letter .example \\enter ur name : sankar The name is: SANKAR (or) enter your name:SAnkar The name is:saNKAR

5 Answers  


what is a function method?give example?

0 Answers  


Is main() is used in the program,,see below example? void main() { int i; for(i=0;i<10;i++) main(); } Then what is the output of the program?

6 Answers  


What do you mean by Recursion Function?

0 Answers   Hexaware,


How can you increase the size of a statically allocated array?

0 Answers   TISL,


Write a c program to print the sizes and ranges of different data types in c?

1 Answers  


How to set file pointer to beginning c?

0 Answers  


What is an object?

5 Answers  


What are Storage Classes in C ?

32 Answers   CTS, HP, IBM, Maharaja Whiteline, Tamil Nadu Open University TNOU, TATA, TCS, Wipro,


Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.

1 Answers   BladeLogic, Infosys,


What is difference between function overloading and operator overloading?

0 Answers  


Categories