KEMBAR78
Infosys - C Strings & Pointers - MCQs | PDF | Pointer (Computer Programming) | Software Development
0% found this document useful (0 votes)
24 views6 pages

Infosys - C Strings & Pointers - MCQs

The document contains multiple-choice questions (MCQs) focused on C strings and pointers, testing knowledge on string manipulation, pointer arithmetic, and memory allocation. Each question provides four answer options, with some questions addressing common misconceptions about string handling in C. The content is designed for individuals familiar with C programming concepts.

Uploaded by

Jack Sparrow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Infosys - C Strings & Pointers - MCQs

The document contains multiple-choice questions (MCQs) focused on C strings and pointers, testing knowledge on string manipulation, pointer arithmetic, and memory allocation. Each question provides four answer options, with some questions addressing common misconceptions about string handling in C. The content is designed for individuals familiar with C programming concepts.

Uploaded by

Jack Sparrow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C Strings & Pointers – MCQs

Q1.

char str[] = "abc";


char *p = str;
printf("%c", *(p + 2));

a) a​
b) b​
c) c​
d) Compilation error

Q2.

char *s = "hello";
printf("%c", *s);

a) h​
b) e​
c) l​
d) o

Q3.​
Which of the following is true?​
a) char *p = "abc"; allows modifying characters via p.​
b) char p[] = "abc"; creates modifiable array on stack.​
c) Both are same in memory.​
d) char *p allocates memory on stack.

Q4.

char s[] = "abcd";


char *p = s;
printf("%s", p + 1);

a) abcd​
b) bcd​
c) cd​
d) Compilation error
Q5.

char s[] = "xyz";


char *p = s;
printf("%c", 2[p]);

a) x​
b) y​
c) z​
d) Compilation error

Q6.​
Which is the correct way to get length using pointers?

char str[] = "hello";

a) strlen(str)​
b) strlen(&str)​
c) sizeof(str)​
d) sizeof(&str)

Q7.

char str[] = "abc";


char *p = str;
printf("%s", p);

a) abc​
b) bc​
c) c​
d) Compilation error

Q8.​
Which statement is correct?​
a) char *p = "abc"; stores characters on stack.​
b) char p[] = "abc"; stores characters in read-only memory.​
c) char p[] = "abc"; creates a modifiable array.​
d) char *p allocates array automatically.
Q9.

char *s = "abc";
printf("%c", *(s+1));

a) a​
b) b​
c) c​
d) Compilation error

Q10.​
Which prints c?

char s[] = "abcd";

a) s[2]​
b) *(s+2)​
c) 2[s]​
d) All of the above

Q11.

char s[] = "hello";


char *p = s + 1;
printf("%s", p);

a) hello​
b) ello​
c) llo​
d) Compilation error

Q12.​
Which is true about string pointer comparison?

char s1[] = "abc";


char s2[] = "abc";
a) s1 == s2 compares content​
b) s1 == s2 compares addresses​
c) strcmp(s1,s2) compares addresses​
d) strcmp compares memory locations

Q13.

char *s = "abc";
printf("%d", strcmp(s,"abc"));

a) 0​
b) 1​
c) -1​
d) Compilation error

Q14.​
Which prints d?

char s[] = "abcd";


printf("%c", *(s+3));

a) a​
b) b​
c) c​
d) d

Q15.​
Correct way to create pointer to first element of array:

char arr[] = "xyz";

a) char *p = arr;​
b) char *p = &arr;​
c) char *p = &arr[0];​
d) a and c

Q16.​
Which prints last character of string s[] = "hello"?​
a) s[4]​
b) *(s+4)​
c) 4[s]​
d) All of the above

Q17.

char *s = "abcdef";
s += 2;
printf("%s", s);

a) abcdef​
b) cdef​
c) def​
d) Compilation error

Q18.​
Which is correct to copy n characters safely?

char src[] = "hello";


char dest[10];

a) strcpy(dest, src)​
b) strncpy(dest, src, 10)​
c) memcpy(dest, src, 10)​
d) sprintf(dest,"%s",src)

Q19.

char s[] = "xyz";


char *p = s + 1;
printf("%c", *p);

a) x​
b) y​
c) z​
d) Compilation error
Q20.

char s[] = "abc";


char *p = s;
printf("%d", *(p+3) == '\0');

a) 0​
b) 1​
c) Depends on compiler​
d) Compilation error

You might also like