Q. How do you convert this char array to string?

Code:
char str[]={'g','l','o','b','y'};
  • (A) str[5] = 0;
  • (B) str[5] = '\0'
  • (C) str[]={'g','l','o','b','y','\0'};
  • (D) All the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All the above

Q. What is the output of C Program?

Code:
int main()
{
    int str[]={'g','l','o','b','y'};
    printf("A%c ",str);
    printf("A%s ",str);
    printf("A%c ",str[0]);
    return 0;
}
  • (A) A A A
  • (B) A Ag Ag
  • (C) A*randomchar* Ag Ag
  • (D) Compiler error
πŸ’¬ Discuss
βœ… Correct Answer: (C) A*randomchar* Ag Ag

Q. What is the output of C Program with arrays?

Code:
int main()
{
    char str[]={"C","A","T","\0"};
    printf("%s",str);
    return 0;
}
  • (A) C
  • (B) CAT
  • (C) CAT\0
  • (D) Compiler error
πŸ’¬ Discuss
βœ… Correct Answer: (D) Compiler error

Q. What is the output of C program with strings?

Code:
int main()
{
    char str1[]="JOHN";
    char str2[20];
    str2= str1;
    printf("%s",str2);
    return 0;
}
  • (A) J
  • (B) JOHN
  • (C) JOHN\0
  • (D) Compiler error
πŸ’¬ Discuss
βœ… Correct Answer: (D) Compiler error

Q. What is the output of C Program with arrays?

Code:
int main()
{
    char str[25];
    scanf("%s", str);
    printf("%s",str);
    return 0;
}
//input: South Africa
  • (A) S
  • (B) South
  • (C) South Africa
  • (D) Compiler error
πŸ’¬ Discuss
βœ… Correct Answer: (B) South

Q. What is the output of C program with strings?

Code:
int main()
{
    char str[2];
    scanf("%s", str);
    printf("%s",str);
    return 0;
}
//Input: South
  • (A) So
  • (B) South
  • (C) Compiler error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) South

Q. What is the output of C Program with strings?

Code:
int main()
{
    char str[2];
    int i=0;
    scanf("%s", str);
    while(str[i] != '\0')
    {
        printf("%c", str[i]);
        i++;
    }
    return 0;
}
//Input: KLMN
  • (A) KL
  • (B) KLMN
  • (C) Compiler error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) KLMN

Q. What is the output of C Program with String Pointer?

Code:
int main()
{
    char country[]="BRAZIL";
    char *ptr;
    ptr=country;
    while(*ptr != '\0')
    {
        printf("%c", *ptr);
        ptr++;
    }
    return 0;
}
  • (A) B
  • (B) BRAZIL
  • (C) Compiler error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) BRAZIL

Q. What is the output of C Program with String Pointers?

Code:
int main()
{
    char *p1 = "GOAT";
    char *p2;
    p2 = p1;
    printf("%s", p2);
}
  • (A) G
  • (B) GOAT
  • (C) Compiler error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) GOAT

Q. What is the output of C Program with String arrays?

Code:
int main()
{
    char *p1 = "GOAT";
    char *p2;
    p2 = p1;
    p2="ANT";
    printf("%s", p1);
}
  • (A) A
  • (B) G
  • (C) GOAT
  • (D) ANT
πŸ’¬ Discuss
βœ… Correct Answer: (C) GOAT