main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
Find the Outputs?
Answers were Sorted based on User's Feedback
Answer / sumeet
Samco Systems
amco Systems
this will be the answer .. the reason being the ascii value
of r will be incremented so it now point to s( capital s
that is ) this account for (*ptr)++
next ptr++ will simply move you to the next charachter ..
| Is This Answer Correct ? | 20 Yes | 7 No |
Answer / ruchi
Turbo c will give an answer
samco system
amco system
pointer ptr is at r
by(*ptr)++ we are incrementing it by one so we get s
by ptr ++ we are incrementing the addrestion of ptr so it
will give an output amco system;
but gcc compiler will not give any answer it will print
segmentation fault
| Is This Answer Correct ? | 7 Yes | 0 No |
Answer / chappa
The first increment is incorrect, since it will try to
increment the value of 'R' but will end up giving
Segmentation fault.
Second ptr++ is valid as it will shift the pointer from 'R'
to 'a'. The second print statement would have printed "amco
Systems", the compiler gives Seg fault due to the previous
incorrect increment.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / dhakchin moorthy.p
first printf stmt prints Ramco Systems
the error is in line ptr++;here u r trying to increment the
address holding by the pointer,pointer var may lost the
starting address.
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / soundar
Address of the variable will be displayed for the first
printf stmt
previous address will be incremented and current address of
variable will displayed for second printf stmt
| Is This Answer Correct ? | 3 Yes | 8 No |
Result of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error
How to explain the final year project as a fresher please answer with sample project
void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result for all case
How can I get Single byte from 'int' type variable? Can we alter single bit or multiple bits in int type variable? if so, How?
what are bit fields in c?
int j =15,i; for (i=1; 1<5; ++i) {printf ("%d%d ",j,i); j = j-3; }
What will be your course of action for a push operation?
What are the different types of objects used in c?
compute the nth mumber in the fibonacci sequence?
10 Answers Canon, HPL, Satyam, TCS,
While(1) { } when this loop get terminate is it a infinite loop?
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output?
If we give two names then this displays the connection between the two people. It is nothing but flames game