Character Array MCQ 5 : Constant Expression as String Size




Character Array MCQ 5 : Constant Expression as String Size


What is the Output of the Following Program ?

#include<stdio.h>
void main()
{
char arr[5*2/2] = {'a','b','c','d','e'};
printf("%c",arr[3]);
}

Options :

  1. Constant Expression Not Allowed
  2. Bound Error
  3. c
  4. d

Output:


Switch to String MCQ Home : Click Here


How and Why ?

char a[5*2/2];
  • Character Array Size Is Always Constant.
  • Constant Expression is Allowed as Size of Character Array.
  • So Following Statements are Legal as –
char a[5*2/2];
char a[5*2*2];
char a[5+2/2];
char a[5*2^2];
char a[5-2/2];
  • Also #define is Allowed –
#define MAX 100
void main()
{
char a[MAX];   // It is Also Allowed
-------------
-------------
-------------
-------------
}