Sail E0 Webinar

MCQs

Total Questions : 37 | Page 2 of 4 pages
Question 11.


What will be the output of the program ?


#include<stdio.h>
#include<string.h>
int main()
{
char sentence[80];
int i;
printf("Enter a line of text\n");
gets(sentence);
for(i=strlen(sentence)-1; i >=0; i--)
putchar(sentence[i]);
return 0;
}
  1.    The sentence will get printed in same order as it entered
  2.    The sentence will get printed in reverse order
  3.    Half of the sentence will get printed
  4.    None of above
 Discuss Question
Answer: Option B. -> The sentence will get printed in reverse order

No answer description available for this question. 


Question 12.


What will be the output of the program ?


#include<stdio.h>
int main()
{
char str1[] = "Hello";
char str2[10];
char *t, *s;
s = str1;
t = str2;
while(*t=*s)
*t++ = *s++;
printf("%s\n", str2);
return 0;
}
  1.    Hello
  2.    HelloHello
  3.    No output
  4.    ello
 Discuss Question
Answer: Option A. -> Hello

No answer description available for this question. 


Question 13.


What will be the output of the program ?


#include<stdio.h>
int main()
{
char str[] = "Nagpur";
str[0]='K';
printf("%s, ", str);
str = "Kanpur";
printf("%s", str+1);
return 0;
}
  1.    Kagpur, Kanpur
  2.    Nagpur, Kanpur
  3.    Kagpur, anpur
  4.    Error
 Discuss Question
Answer: Option D. -> Error

The statement str = "Kanpur"; generates the LVALUE required error. We have to 

use strcpy function to copy a string.

To remove error we have to change this statement str = "Kanpur"; to strcpy(str, "Kanpur");

The program prints the string "anpur"


Question 14.


What will be the output of the program ?


#include<stdio.h>
int main()
{
static char mess[6][30] = {"Don't walk in front of me...",
"I may not follow;",
"Don't walk behind me...",
"Just walk beside me...",
"And be my friend." };
printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));
return 0;
}
  1.    t, t
  2.    k, k
  3.    n, k
  4.    m, f
 Discuss Question
Answer: Option B. -> k, k

No answer description available for this question. 


Question 15.


If the size of pointer is 32 bits What will be the output of the program ?


#include<stdio.h>
int main()
{
char a[] = "Visual C++";
char *b = "Visual C++";
printf("%d, %d\n", sizeof(a), sizeof(b));
printf("%d, %d", sizeof(*a), sizeof(*b));
return 0;
}
A. 10, 2
2, 2
B. 10, 4
1, 2
C. 11, 4
1, 1
D. 12, 2
2, 2
  1.    t, t
  2.    k, k
  3.    n, k
  4.    m, f
 Discuss Question
Answer: Option B. -> k, k

Answer: (C)

No answer description available for this question. 


Question 16.


If char=1, int=4, and float=4 bytes size, What will be the output of the program ?


#include<stdio.h>
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
  1.    1, 2, 4
  2.    1, 4, 4
  3.    2, 2, 4
  4.    2, 4, 8
 Discuss Question
Answer: Option B. -> 1, 4, 4

Step 1: char ch = 'A'; The variable ch is declared as an character type and

 initialized with value 'A'.

Step 2:

printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));

The sizeof function returns the size of the given expression.

sizeof(ch) becomes sizeof(char). The size of char is 1 byte.

sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question).

sizeof(3.14f). The size of float is 4 bytes.

Hence the output of the program is 1, 4, 4


Question 17.


What will be the output of the program ?


#include<stdio.h>
int main()
{
int i;
char a[] = "\0";
if(printf("%s", a))
printf("The string is empty\n");
else
printf("The string is not empty\n");
return 0;
}
  1.    The string is empty
  2.    The string is not empty
  3.    No output
  4.    0
 Discuss Question
Answer: Option B. -> The string is not empty

The function printf() returns the number of charecters printed on the console.

Step 1: char a[] = "�"; The variable a is declared as an array of characters and it

 initialized with "�". It denotes that the string is empty.

Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns

 '0'(zero). Hence the if condition is failed.

In the else part it prints "The string is not empty".


Question 18.


What will be the output of the program in 16-bit platform (Turbo C under DOS) ?


#include<stdio.h>
int main()
{
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
return 0;
}
  1.    8, 1, 4
  2.    4, 2, 8
  3.    4, 2, 4
  4.    10, 3, 4
 Discuss Question
Answer: Option B. -> 4, 2, 8

Step 1:

printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));

The sizeof function returns the size of the given expression.

sizeof(3.0f) is a floating point constant. The size of float is 4 bytes

sizeof('3') It converts '3' in to ASCII value.. The size of int is 2 bytes

sizeof(3.0) is a double constant. The size of double is 8 bytes

Hence the output of the program is 4,2,8

Note: The above program may produce different output in other platform due to the platform dependency of C compiler.

In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.


Question 19.


What will be the output of the program ?


#include<stdio.h>
int main()
{
static char s[25] = "The cocaine man";
int i=0;
char ch;
ch = s[++i];
printf("%c", ch);
ch = s[i++];
printf("%c", ch);
ch = i++[s];
printf("%c", ch);
ch = ++i[s];
printf("%c", ch);
return 0;
}
  1.    hhe!
  2.    he c
  3.    The c
  4.    Hhec
 Discuss Question
Answer: Option A. -> hhe!

No answer description available for this question. 


Question 20.


What will be the output of the program ?


#include<stdio.h>
#include<string.h>
int main()
{
static char s[] = "Hello!";
printf("%d\n", *(s+strlen(s)));
return 0;
}
  1.    8
  2.    0
  3.    16
  4.    Error
 Discuss Question
Answer: Option B. -> 0

No answer description available for this question. 


Latest Videos

Latest Test Papers