About c programming

  1. What is the output of
    main ( )
    char ch [20];
    int i;
    for (i=0; i<19; i++)
    *(ch +i)=67;
    *(ch +i)=’\0’;
    a) Prints c 20 times
    b) Prints c 18 times
    c) Prints c 17 times
    d) Prints c 19 times


Answer must be D since the ‘\0’ is treated as null character in string so you are running the loop for 19 times and storing c in each position and at last part that is ch[19] you are storing Null so printed will terminate after seeing the NULL so it prints 19 c’s


yes ur answer is right