Strings

Q1: What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str[] = "Nagpur";
    str[0]='K';
    printf("%s, ", str);
    str = "Kanpur";
    printf("%s", str+1);
    return 0;
}

A Kagpur, Kanpur

B Nagpur, Kanpur

C Kagpur, anpur

D Error

ANS:D - Error

The statement str = "Kanpur"; generates the LVALUE required error. We have to use strcpy function to copy a string. To remove error we have to change this statement str = "Kanpur"; to strcpy(str, "Kanpur"); The program prints the string "anpur"



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.