What is the output of the following C code? int main () { int x = 5; printf("%dn", x++); return 0;

Review the verified answer and explanation for this SPSC – Sindh Public Service Commission past-paper question on CampusFin.

What is the output of the following C code? int main () { int x = 5; printf("%dn", x++); return 0; Answer: 5

• Initialization: The variable x is declared and initialized with the value of 5. • Post-increment operator (x++): In C, the post-increment operator means that the variable's original value is used in the expression first. The variable is only incremented after the expression has been evaluated. • printf function: The printf function receives the current value of x, which is 5, and prints it to the standard output. • Increment: After the printf function has executed and used the value of x, x is then incremented to 6. This change is not reflected in the output of the printf call because it happened after the function was given the value to print.

Question context

This question is part of 💡 C Programming within the broader 💻 Programming subject and appears in the SPSC – Sindh Public Service Commission preparation collection. Reviewing the answer together with nearby questions helps reinforce the underlying concept and identify how it may appear in competitive exams.