Open In App
Related Articles

C | Operators | Question 12

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
#include<stdio.h> 
int main() 
  char *s[] = { "knowledge","is","power"}; 
  char **p; 
  p = s; 
  printf("%s ", ++*p); 
  printf("%s ", *p++); 
  printf("%s ", ++*p); 
    
  return 0; 
}

                    
(A) is power (B) nowledge nowledge s (C) is ower (D) nowledge knowledge is

Answer: (B)

Explanation: Let us consider the expression ++*p in first printf(). Since precedence of prefix ++ and * is same, associativity comes into picture. *p is evaluated first because both prefix ++ and * are right to left associative. When we increment *p by 1, it starts pointing to second character of “knowledge”. Therefore, the first printf statement prints “nowledge”. Let us consider the expression *p++ in second printf() . Since precedence of postfix ++ is higher than *, p++ is evaluated first. And since it’s a postfix ++, old value of p is used in this expression. Therefore, second printf statement prints “nowledge”. In third printf statement, the new value of p (updated by second printf) is used, and third printf() prints “s”.

Quiz of this Question

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Last Updated : 12 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads