basicc++mcq

C MCQ Questions and Answers on Strings, Char Arrays and Pointers 2 | c programming mcq questions answer

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 the ASCII value of NULL or .?

A) 0

B) 1

C) 10

D) 49

Answer [=]

A

Explanation:

ASCII value of NULL character is ZERO 0.

2) A character constant is enclosed by.?

A) Left Single Quotes

B) Right Single Quotes

C) Double Quotes

D) None of the above

Answer [=]

B

Explanation:

char ary[] = {‘a’,’b’,’’}.

char bry[] = {`a`,`b`,`c`}; is wrong as it uses Left Single Quotes.

3) Choose a correct statement about C String.

A) A string is a group of characters enclosed by double quotes.

B) If a string is defined with double quotes, NULL is automatically added at the end.

C) Size of a string is without counting NULL character at the end

D) All the above

Answer [=]

D

4) A C string elements are always stored in.?

A) Random memory locations

B) Alternate memory locations

C) Sequential memory locations

D) None of the above

Answer [=]

C

5) What is the output of C program with strings.?

int main()

{

    char var=’b’;

    printf(“%d “, sizeof(“a”));

    printf(“%d “, sizeof(‘b’));

    printf(“%d “, sizeof(10));

    printf(“%d “, sizeof(var));

}

//int size is 2 bytes

A) 1 1 1 1

B) 2 1 2 1

C) 2 2 2 1

D) 2 2 2 2

Answer [=]

C

Explanation:

sizeof(‘b’) is 2 because ‘b’ is converted to ASCII number which is integer. sizeof(var) is printed as expected. size(“a”) is two because NULL occupies 1 byte.

6) What is the output of C program with strings.?

int main()

{

    char str[]=”JACKIE CHAN”;

    int i=0;

    while(str[i] != 0)

    {

        printf(“%c”,str[i]);

        i++;

    }

    return 0;

}

A) JJJJJJ JJJJ

B) JACKIE CHAN

C) Compiler error

D) None of the above

Answer [=]

B

Explanation:

Yes. You can check for end of a string with ASCII ZERO 0. ASCII value of NULL or is ZERO.

7) What is the output of C program with strings.?

int main()

{

    char str[]=”ANDAMAN”;

    int i=0;

    while(str[i] != ‘’)

    {

        printf(“%c”,str[i]);

        i++;

    }

    return 0;

}

A) AAAAAAA

B) ANDAMAN

C) Compiler error

D) None of the above

Answer [=]

B



8) What is the output of C program with strings.?

int main()

{

    char str[]=”MALDIVES”;

    printf(“%s “,str);

    puts(str);

    return 0;

}

A) MALDIVES

B) MALDIVES MALDIVES

C) M MALDIVES

D) None of the above

Answer [=]

B

Explanation:

PUTS prints strings without any format specifier like %s.

9) What is the output of C program with strings.?

int main()

{

    char str[3]=”SUNDAY”;

    printf(“%s”,str);

}

A) SUN

B) SUNgarbagevalues

C) compiler error

D) None of the above

Answer [=]

B

Explanation:

You get C warning.z

warning: initializer-string for array of chars is too long

10) Choose a correct C statement about String functions.?

A) int n=strlen(“abc”) returns 3.

B) strupr(“abc”) returns ABC

C) strlwr(“Abc”) returns abc

D) All the above

Answer [=]

D

11) Choose a correct C statement about String functions.?

A) strrev(“abcD”) returns Dcba.

B) strcmp(“abc”, “bcd”) returns a negative number

C) strcmp(“234″,”123”) returns a positive number

D) All the above

Answer [=]

D

12) Choose a correct C statement about String functions.?

A) toupper(‘a’) returns A

B) tolower(‘D’) returns d.

C) strcmp(“123″,”12345”) returns a negative number

D) All the above

Answer [=]

D

13) What is the output of C program.?

int main()

{

    char str1[]=”JAMES,”;

    char str2[15]=”BOND “;

    strcat(str2,str1);

    printf(“%s”,str2);

    printf(“%s”,str1);

}

A) JAMES BOND,JAMES,

B) JAMES,JAMES,

C) BOND JAMES,JAMES,

D) None of the above

Answer [=]

C

Explanation:

Here str1 is not affected by strcat function. STRCAT(destination, source).

14) What is the output of C program.?

int main()

{

    printf(“%c”,”HUMPTY”[2]);

}

A) U

B) M

C) HUMPTY

D) None of the above

Answer [=]

B



15) What is the output of C program.?

int main()

{

    char str1[] = “FIRST”;

    char str2[20];

    strcpy(str2,str1);

    printf(“%s %s “,str1,str2);

    printf(“%d”, (str1!=str2));

    printf(“%d”, strcmp(str1,str2));

    return 0;

}

A) FIRST FIRST 0 0

B) FIRST FIRST 1 1

C) FIRST FIRST 1 0

D) FIRST FIRST 0 1

Answer [=]

C

Explanation:

STRCPY copies STR1 value to another memory location pointed by STR2. Only STR1 and STR2 values are same but not memory locations.

16) What is the output of C program with array of pointers to strings.?

int main()

{

    char *code[]={“IN”,”USA”,”K”};

    printf(“%s”, code[1]);

    return 0;

}

A) IN

B) U

C) USA

D) Compiler error

Answer [=]

C

Explanation:

It is an array of arrays. Using an array of pointers to strings, we can save memory. Different strings can have different lengths. Other wise, max length of any element should be the length of all elements. It wastes space.

17) What is the output of C program with String arrays.?

int main()

{

    char code[3][4]={“IN”,”USA”,”K”};

    printf(“%s”, code[1]);

    return 0;

}

A) IN

B) USA

C) K

D) Compiler error

Answer [=]

B

Explanation:

Here, we have not used pointers to strings. So a total of 3×4=12 bytes is allocated. Using a pointers to strings, we can allocate just 3+4+2=9 bytes. Extra byte stores NULL or . USA+null = 4 characters.

18) What is the output of C program with array of pointers to strings.?

int main()

{

    char *code[2];

    code[0]= (char *)malloc(4);

    strcpy(code[0], “IND”);

    printf(“%s”, code[0]);

    return 0;

}

A) I

B) IN

C) IND

D) Compiler error

Answer [=]

C

Explanation:

If you use a pointer to string instead of char str[], you should use malloc() or calloc() to allocate memory and then write some data like “IND” into it. Otherwise, your output will be unexpected.

19) What is actually passed to PRINTF or SCANF functions.?

A) Value of String

B) Address of String

C) End address of String

D) Integer equivalent value of String

Answer [=]

B

Explanation:

printf(“Hello”) takes the address of “Hello” and processes till it reaches NULL or .

20) What is the output of C program with strings.?

int main()

{

    char *code=”JUMPER”;

    if(code[6]==’o’)

    {

        printf(“SUMMER”);

    }

    else

    {

        printf(“WINTER”);

    }

    return 0;

}

A) SUMMER

B) WINTER

C) Compiler error

D) None of the above

Answer [=]

B

Explanation:

SLASH O is different from SLASH ZERO. Use ‘’ to get end of string.

 

Leave a Reply

10 Best Artificial Intelligence Software|artificial intelligence tools 5 nft games to earn money | Best NFT games for earn crypto Earn Money From Minting NFTs| How to mint NFT for free Top 10 Things You Need To Know About Python List | python lists functions 10 Popular PHP frameworks for web developers| best php frameworks 12 Tips On How To Become a Python Developer | python For beginner 12 Best Nodejs Frameworks for App Development in 2022 how to create google web stories, Steps to create web stories Top 10 Features in Angular 13 Every Developer Should Know | Angular 13 Features 10 Best Angular UI Libraries | angular ui components | angular Project 10 Best Web Development Frameworks in 2022 Frontend & Backend 18 Best Open-Source and Free Database Software | best database software for beginners Top 10+ Best Java IDEs & Online Java Compilers | best java ide for beginners top 10 besic to andvance java books |java books for beginer Top 5 Themes For Blogger, professional blogger theme download BEST Python Courses Online,Top 10 Courses to Learn Python in 2022 Top 13 python libraries for data science