Printf MCQ 24 : Character array of Length = 2 Assigned to Character Variable



Printf Multiple Choice Questions 24  : Character array of Length = 2 Assigned to Character Variable


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

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

Options :

  1. A
  2. AB
  3. Compile Error
  4. Run Time Error

[toggle title=”Output”]A[/toggle]


Switch to Printf MCQ Home :  Click Here


How and Why ?

  1. Output is ‘A’ is Printed
  2. Reason being that , Character Variable can atmost array of Two Characters
  3. Example ‘n’ Though it has two Characters but it is Interpreted as Single Character , Similarly ‘AB’ is theoratically considered as Single Variable

Rule :

  1. Character Variable can Store atmost Two Characters