C-Strings Question and Answer

C-Strings Question and Answer
11. char *a="23422"; sozeof (a), strlen(a));
From the above, what is the output of the printf function ?
  • 4 4
  • 5 5
  • 5 4
  • 4 5
Show Answer
12. 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 ?
  • IT is department no 1 of MIT
  • L value required RUNTIME ERROR
  • IT is department no-1 of MIT
  • compilation error
Show Answer
13. char *p;
char name [25] = "MIT-IT";
strcpy (p,name);
printf("%s",p);
What will be the output?

  • segmentation fault because pointer p is only declared but no memory allocated
  • compilation error
  • MIT-IT
  • none of the above
Show Answer
14. 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
  • in both cases, the total amount of memory allocated will be the same
  • the total amount of memory allocated difffers based on the input
  • based on the compiler options
  • both (a) and (c)
Show Answer
15. char *name = "Delhi";
printf ("%d %d", sizeo (name), sizeof ()*name));
What will be the output?
  • 4 1
  • 4 4
  • 5 1
  • 5 4
Show Answer
16. 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));
}




  • 5 sales 5
  • 11 sales 9
  • 11 sales man 9
  • 11 sales 5
Show Answer
17. Which of the following is the correct output for the program given ?
char str [7] = "strings"; printf ("%s", str);
  • error
  • strings
  • cannot predict
  • none of the above
Show Answer
18. 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));
}

  • 1 4 2
  • 1 4 8
  • 2 2 4
  • 2 4 8
Show Answer
19. 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);
}
  • compilation error because strcat does not return a value
  • united front
  • segmentation fault because str3 might be pointing to a ggarbage value
  • united
Show Answer
20. 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
  • (2) only
  • (1) only
  • (1) and (2)
  • (2) and (3)
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test