Printf Multiple Choice Questions 23 : Character array Assigned to Character Variable


Predict the Output of the Following Program if Given Things are -

#include<stdio.h>
void main()
{
char ch = 'ABCDEF';
printf("%c",ch);
}

Options :

  1. A
  2. ABCDEF
  3. Compile Error
  4. Run Time Error
[toggle title="Output"]Compile Error[/toggle]

Switch to Printf MCQ Home : Click Here


How and Why ?

  1. Confused !!! Why You get Compile Time Error ?
  2. Reason being that , Character Variable can Store Single Character
  3. ch is character Type and ‘ABCDEF’ is String and Shown in Single Quotes which violets the Definition of Character and Array of Character