0 votes 0 votes Find the output of the following c code- main() { char *ptr="gatebuddy"; *(ptr)++; ptr++; printf("%s\n",ptr); } Programming in C programming-in-c pointers + – debanjan sarkar asked Aug 21, 2015 • edited Aug 30, 2023 by Hira Thakur debanjan sarkar 1.1k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
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 Digvijay Pandey answered Aug 21, 2015 • selected Aug 23, 2015 by debanjan sarkar Digvijay Pandey comment Share Follow See all 0 reply Please log in or register to add a comment.