ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
int *p=20;
if u print like dis printf("%d",p);
o\p:- 20; how is it possible?
plz give me the explanation.
 Question Submitted By :: Vishnu948923
I also faced this Question!!     Rank Answer Posted By  
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 1
Because you're printing p, not *p. scanf takes addresses of 
variables as arguments, but printf does not.
 
Is This Answer Correct ?    1 Yes 3 No
Lylez00
[Acxiom]
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 2
ya,, i think.. 
        first we have declared an pointer variable *p and
assigned a value 20.... but we know that pointers are those
which can hold only the address of another variable..... so
surely in the memory P it wont have 20... so 20 will be
stored in some other unbknown variable in the memory which
wont be visible to user in thesr cases...... that unknown
memory address will be getting stored in this pointer
variable....   so when we give only p or *p it will print 20
and not the address of the unknown location containing
20........... because it will be directly accessible
 
Is This Answer Correct ?    1 Yes 3 No
Vignesh1988i
 
 
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 3
It will not compile. You cant do int *p = 20;
 
Is This Answer Correct ?    7 Yes 8 No
Jack
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 4
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 ?    10 Yes 3 No
Santhi Perumal
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 5
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 ?    1 Yes 3 No
Sateeshbabu Aluri
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 6
printf("%p",p); // this prints the address to 20

printf("%d",p); //this prints the value itself.
 
Is This Answer Correct ?    1 Yes 1 No
Immanuel
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 7
this will result in error.... pointer itself cant point to
any value... we, the users must make an explict assignment
for the pointer to point to an value .....
 
Is This Answer Correct ?    3 Yes 4 No
Vignesh1988i
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 8
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 ?    1 Yes 2 No
Valli
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 9
GIVES THE ERROR DURING COMPILATION.
*P means IT CAN STORE ADDRESS NOT ANY INTEGER VALUE.
 
Is This Answer Correct ?    1 Yes 2 No
Thunder
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 10
it will show compiler error as we are trying to assign integer value to pointer variable.
 
Is This Answer Correct ?    0 Yes 1 No
Ankit
 
  Re: int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Answer
# 11
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 ?    0 Yes 0 No
Saikishore
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Program to find the value of e raised to power x using while loop N-Tech3
Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning Accenture4
24.what is a void pointer? 25.why arithmetic operation can’t be performed on a void pointer? 26.differentiate between const char *a; char *const a; and char const *a; 27.compare array with pointer? 28.what is a NULL pointer? 29.what does ‘segmentation violation’ mean? 30.what does ‘Bus Error’ mean? 31.Define function pointers? 32.How do you initialize function pointers? Give an example? 33.where can function pointers be used?  1
write a program to print sum of each row of a 2D array.  2
Determine the code below, tell me exactly how many times is the operation sum++ performed ? for ( i = 0; i < 100; i++ ) for ( j = 100; j > 100 - i; j--) sum++; ITCO3
what are the static variables HCL7
main() { char *p; p="Hello"; printf("%c\n",*&*p); } ME2
Write a program to find the smallest and largest element in a given array in c language Microsoft3
What is the output for the following program #include<stdio.h> main() { char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0])); printf("%d\n",flag); } ADITI5
Please list all the unary and binary operators in C.  1
WHAT IS THE DIFFERANCE BITWIN GETS();AND SCANF();  2
what is dangling pointer? LG-Soft1
I use turbo C which allocates 2 bytes for integers and 4 bytes for long. I tried to declare array of size 500000 of long type using the following code... long *arr; arr=(long *)(malloc)(500000 * sizeof(long)); It gives a warning that "Conversion may lose significant digits in function main"... And the resulting array size was very less around 8400 as compared to 500000. Any suggestions will be welcomed....  2
What is the output of the following program #include<stdio.h> main() { int i=0; fork(); printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); } ADITI5
declare afunction pointer to int printf(char *)? HCL1
How to receive strings with spaces in scanf()  4
difference between semaphores and mutex?  1
How can we open a file in Binary mode and Text mode?what is the difference? PanTerra1
without using arithmatic operator solve which number is greater??????????  1
write a c program to find biggest of 3 number without relational operator? Wipro2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com