edited by
1,145 views

1 Answer

Best answer
5 votes
5 votes

char *ptr="gatebuddy"; // ptr is a pointer variable pointing to a string literal 'gatebuddy'. C by default adds a null character (\0) at the end of any string literal.

*(ptr)++;      // ptr point 2nd element of string literal 'gatebuddy' as postincrement has higher precedence than indirection. 

Ref: http://en.cppreference.com/w/c/language/operator_precedence

ptr++;       // ptr point 3rd element of string literal 'gatebuddy'

printf("%s\n",ptr);  //it ll print all character of string from 3rd element to that index where null character is stored.

i.e.   it will print tebuddy

selected by

Related questions

603
views
2 answers
1 votes
Anurag_s asked Oct 18, 2015
603 views
consider following code segment  in cmain(){char * z="abc";z[0]='x';printf("%s",z);}what will be behavior of the programa>compiler error   b>runtime error c>no error prints xbcd>no error prints abc
815
views
1 answers
0 votes
stblue asked Oct 18, 2017
815 views
#include <stdio.h>int main(){ int a[] = {50, 60, 10, 30, 40, 20 }; int *b[] = {a+3, a+4, a, a+2, a+1, a+5 }; int **c = b; c++; printf("%u, %u, %u\n", c-b, *c - a, **c); return 0;}
1.2k
views
2 answers
0 votes
Desert_Warrior asked May 16, 2016
1,215 views
#include <stdio.h> int main() { int a[][3] = {1, 2, 3, 4, 5, 6}; int (*ptr)[3] = a; // LINE 5 printf("%d %d ", (*ptr)[1], (*ptr)[2]); //LINE 6 ++ptr; printf("%d %d ... ]); return 0; }(a) 2 3 5 6 (b) 2 3 4 5 (c) 4 5 0 0 (d) none of the above
1.4k
views
1 answers
7 votes
Desert_Warrior asked May 16, 2016
1,418 views
#include <stdio.h> void f(char**); int main() { char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" }; f(argv); return 0; } void f(char **p) { ... }(a) ab (b) cd (c) ef (d) ghIn GATE Exam, if not specified What should be size of integer?