C MCQ Questions and Answers on Strings, Char Arrays and Pointers 1

Image

Study C MCQ Questions and Answers on Strings, Character Arrays, String Pointers and Char Pointers. Easily attend technical job interviews after practising the Multiple Choice Questions.

Go through C Theory Notes on Strings before studying questions.



1) What is a String in C Language.?
A) String is a new Data Type in C
B) String is an array of Characters with null character as the last element of array.
C) String is an array of Characters with null character as the first element of array
D) String is an array of Integers with 0 as the last element of array.
Answer [=]
Answer[=]
2) Choose a correct statement about C String.
char ary[]="Hello..!";
A) Character array, ary is a string.
B) ary has no Null character at the end
C) String size is not mentioned
D) String can not contain special characters.
Answer [=]
Answer[=]
3) What is the Format specifier used to print a String or Character array in C Printf or Scanf function.?
A) %c
B) %C
C) %s
D) %w
Answer [=]
Answer[=]
4) What is the output of C Program with Strings.?
int main()
{
    char ary[]="Discovery Channel";
    printf("%s",ary);
    return 0;
}
A) D
B) Discovery Channel
C) Discovery
D) Compiler error
Answer [=]
Answer[=]
5) What is the output of C Program with Strings.?
int main()
{
    char str[]={'g','l','o','b','e'};
    printf("%s",str);
    return 0;
}
A) g
B) globe
C) globe\0
D) None of the above
Answer [=]
Answer[=]
6) What is the output of C Program with Strings.?
int main()
{
    char str[]={'g','l','o','b','y','\0'};
    printf("%s",str);
    return 0;
}
A) g
B) globe
C) globe\0
D) Compiler error
Answer [=]
Answer[=]
7) How do you convert this char array to string.?
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
Answer [=]
Answer[=]


 

8) What is the output of C Program.?
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
Answer [=]
Answer[=]
9) What is the output of C Program with arrays.?
int main()
{
    char str[]={"C","A","T","\0"};
    printf("%s",str);
    return 0;
}
A) C
B) CAT
C) CAT\0
D) Compiler error
Answer [=]
Answer[=]
10) What is the maximum length of a C String.?
A) 32 characters
B) 64 characters
C) 256 characters
D) None of the above
Answer [=]
Answer[=]
11) What is the output of C program with strings.?
int main()
{
    char str1[]="JOHN";
    char str2[20];
    str2= str1;
    printf("%s",str2);
    return 0;
}
A) JOHN
B) J
C) JOHN\0
D) Compiler error
Answer [=]
Answer[=]
12) What is the output of C Program with arrays.?
int main()
{
    char str[25];
    scanf("%s", str);
    printf("%s",str);
    return 0;
}
//input: South Africa
A) South
B) South Africa
C) S
D) Compiler error
Answer [=]
Answer[=]
13) What is the output of C program with strings.?
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
Answer [=]
Answer[=]
14) What is the output of C Program with strings.?
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
Answer [=]
Answer[=]


 

15) What is the output of C Program with String Pointer.?
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
Answer [=]
Answer[=]
16) How do you accept a Multi Word Input in C Language.?
A) SCANF
B) GETS
C) GETC
D) FINDS
Answer [=]
Answer[=]
17) Choose a correct C Statement about Strings.
A) PRINTF is capable of printing a multi word string.
B) PUTS is capable of printing a multi word string.
C) GETS is capable of accepting a multi word string from console or command prompt
D) All the above
Answer [=]
Answer[=]
18) What is the output of C Program with String Pointers.?
int main()
{
    char *p1 = "GOAT";
    char *p2;
    p2 = p1;
    printf("%s", p2);
}
A) G
B) GOAT
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
19) What is the output of C Program with String arrays.?
int main()
{
    char *p1 = "GOAT";
    char *p2;
    p2 = p1;
    p2="ANT";
    printf("%s", p1);
}
A) ANT
B) GOAT
C) G
D) A
Answer [=]
Answer[=]
20) What is the output of C Program with String Arrays.?
int main()
{
    char p[] = "GODZILLA";
    int i=0;
    while(p[i] != '\0')
    {
        printf("%c",*(p+i));
        i++;
    }
}
A) G
B) GODZILLA
C) Compiler error
D) None of the above
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Some good C Books

Book Price
1. C: The Complete Reference  Check Price
2. Let Us C Check Price
3. Programming in ANSI C Check Price
4. The C Programming Language Check Price

We may get some affiliate commission for the above purchases.