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   SiteMap shows list of All Categories in this site.
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
what is the difference between these initializations? 
Char a[]=”string”; 
Char *p=”literal”; 
Does *p++ increment p, or what it points to?
 Question Submitted By :: A. Sujatha
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is the difference between these initializations? Char a[]=”string”; Char *p=”literal”; Does *p++ increment p, or what it points to?
Answer
# 1
surely there is some difference.....

here 'a' is represented as array in which string gets stored
in consecutive locations......

p is a pointer variable where string is initilized... so in
p the base address of "literal " will get stored...... 

*p++ increments 'p' , but pertaining to some conditions.....
++ has more precedence than * , so first it will increment
the address and correspondingly it will show the value as *
precedes..... so after the increment the p points to 'i'...



thank u
 
Is This Answer Correct ?    2 Yes 0 No
Vignesh1988i
 
  Re: what is the difference between these initializations? Char a[]=”string”; Char *p=”literal”; Does *p++ increment p, or what it points to?
Answer
# 2
I am totally satisfied with your above explanation except
last one. 
i.e.  Char *p="literal";
So, i want to mention yes this will work.
Explanation: *p++. 
Here we have post increment. 
Postfix increment/decrement have high precedence, but the
actual increment or decrement of the operand is delayed (to
be accomplished sometime before the statement completes
execution).
value of printf("\nstr=%c\n",*p++) will be 'l', but before
complete execution of this statement p will point to string
"iteral" as p got incremented.
 
Is This Answer Correct ?    1 Yes 0 No
Gaurav
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
If 4 digits number is input through the keyboard, Write a program to calculate sum of its 1st & 4th digit.  4
how the size of an integer is decided? - is it based on processor or compiler or OS? nvidia16
class foo { public: static int func(const char*& p) const; }; This is illegal, why? Google6
what is a function pointer and how all to declare ,define and implement it ??? Honeywell3
what is y value of the code if input x=10 y=5; if (x==10) else if(x==9) elae y=8; a.9 b.8 c.6 d.7 TCS2
How can we see the Expanded source code and compiled code for our source program in C?  1
How many types of linked lists what are they? How many types of data structures? BSNL5
Predict the output or error(s) for the following: 25. main() { printf("%p",main); } ME3
What is the difference between char a[] = "string"; and char *p = "string"; ? Honeywell11
What are .h files and what should I put in them?  3
How to set a variable in the environment list?  1
how does printf function work  1
What will be printed as the result of the operation below: #include<..> int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changevalue(x); printf("Second output:%d\n",x); modifyvalue(); printf("Third output:%d\n",x); }  2
consider the following program sigment int n,sum=1; switch(n) { case 2:sum=sum+2; case 3:sum*=2; break; default:sum=0;} if n=2, what is the value of sum a.0 b.6 c.3 d.none TCS4
Write a C++ program without using any loop (if, for, while etc) to print numbers from 1 to 100 and 100 to 1;  7
what is the output of the following program? #include<stdio.h> void main() { int x=4,y=3,z; z=x-- -y; printf("\n%d %d %d",x,y,z); }  10
What is the memory allocated by the following definition ? int (*x)[10]; ADITI3
6)swap(int x,y) { int temp; temp=x; x=y; y=temp; } main() { int x=2;y=3; swap(x,y); } after calling swap ,what are yhe values x&y?  2
char S; char S[6]= " HELLO"; printf("%s ",S[6]); output of the above program ? (0, ASCII 0, I,unpredictable) Mascot6
Why cann't whole array can be passed to function as value.  1
 
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