C Programming :: String - Discussion
Home > C Programming > String > MCQs Questions Discussion
5 / 26
What is the output of the following problem ?
#include<stdio.h>
void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("Value of i %d\n",++i);
}
#include<stdio.h>
void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("Value of i %d\n",++i);
}
AValue of i 6
BValue of i 5
CValue of i 7
DCompilation Error
ENone of these
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
STEP-BY-STEP
The character array 'a' contains 6 characters i.e, '1', '2', '3', '4', '5', and '\0'. But, the C compiler does not count the '\0' character as it is a Zero character used to indicate the termination of a character string in C. So, value of i will be equal to 5, and not 6. But, in line no. 6, we are pre-incrementing the value of 'i' by 1. So, the value of 'i' which will get displayed is 6 i.e, option A.
Read Full Answer
Report Error
Please Login First Click Here