C Strings Questions and Answers

Practice Mode
Showing 10 of 26 questions
Q11
char *a="23422"; sozeof (a), strlen(a)); From the above, what is the output of the printf function ?
  • A 4 4
  • B 5 5
  • C 5 4
  • D 4 5
Answer: Option D
Q12
char name [ ] = 'MIT' printf ("%s is deprtment %s %d of %s/n', &name [1], "no", ('A' 'a')/", name); From the above, what is the output of the printf statement ?
  • A IT is department no 1 of MIT
  • B L value required RUNTIME ERROR
  • C IT is department no-1 of MIT
  • D compilation error
Answer: Option C
Q13
char *p; char name [25] = "MIT-IT"; strcpy (p,name); printf("%s",p); What will be the output?
  • A segmentation fault because pointer p is only declared but no memory allocated
  • B compilation error
  • C MIT-IT
  • D none of the above
Answer: Option A
Q14
char name [10]; scanf ("%s", name); if (strcmp (name, "chennai") = = 0 { char a[10] = "600028"; printf ("Mandaveli has the pin code: %s\n",a); } What will be the amount of memory allocated in the following cases'? case 1 input is not chennai, case 2 input is chennai
  • A in both cases, the total amount of memory allocated will be the same
  • B the total amount of memory allocated difffers based on the input
  • C based on the compiler options
  • D both (a) and (c)
Answer: Option A
Q15
char *name = "Delhi"; printf ("%d %d", sizeo (name), sizeof ()*name)); What will be the output?
  • A 4 1
  • B 4 4
  • C 5 1
  • D 5 4
Answer: Option A
Q16
Which of the following is the correct output for the program given? main ( ) { char str [ ]="Sales \0man\0"; printf ("%d %s %d \n", sizeof (str), strlen (str)); }
  • A 5 sales 5
  • B 11 sales 9
  • C 11 sales man 9
  • D 11 sales 5
Answer: Option D
Q17
Which of the following is the correct output for the program given ? char str [7] = "strings"; printf ("%s", str);
  • A error
  • B strings
  • C cannot predict
  • D none of the above
Answer: Option C
Q18
If sizes of a char, an int, a float and a double are 1, 4, 4 and 8 bytes respectively, which of the following is the correct output for the program given below? { char ch = 'A'; printf ("%d%d%d", sizeof (ch), sizeof (sizeof('A')), sizeof (3 . 14)); }
  • A 1 4 2
  • B 1 4 8
  • C 2 2 4
  • D 2 4 8
Answer: Option B
Q19
What is the value of str3 and sdtr1; void main ( ) { char str1 [100] = "united"; char *str2="front"; char *str3; str3 = strcat (str1, str2) printf ("\n////5s", str3); }
  • A compilation error because strcat does not return a value
  • B united front
  • C segmentation fault because str3 might be pointing to a ggarbage value
  • D united
Answer: Option B
Q20
Consider the following declarations: char *a; char a[5]; Which of the following statements is/are true? 1. both are of pointer type 2. memory allocation is different in both the cases 3. the value of a in drclaration char a [5] can be changed later
  • A (2) only
  • B (1) only
  • C (1) and (2)
  • D (2) and (3)
Answer: Option A
Questions and Answers for Competitive Exams Various Entrance Test