Sail E0 Webinar

MCQs

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


Which of the following statement is correct about the program?


#include<stdio.h>
int main()
{
FILE *fp;
char str[11], ch;
int i=0;
fp = fopen("INPUT.TXT", "r");
while((ch=getc(fp))!=EOF)
{
if(ch == '\n' || ch == ' ')
{
str[i]='\0';
strrev(str);
printf("%s", str);
i=0;
}
else
str[i++]=ch;
}
fclose(fp);
return 0;
}
  1.    The code writes a text to a file
  2.    The code reads a text files and display its content in reverse order
  3.    The code writes a text to a file in reverse order
  4.    None of above
 Discuss Question
Answer: Option B. -> The code reads a text files and display its content in reverse order

This program reads the file INPUT.TXT and store it in the string str after reversing 

the string using strrev function.

Question 12.


Which of the following statement is correct about the program?


#include<stdio.h>
int main()
{
FILE *fp;
char ch;
int i=1;
fp = fopen("myfile.c", "r");
while((ch=getc(fp))!=EOF)
{
if(ch == '\n')
i++;
}
fclose(fp);
return 0;
}
  1.    The code counts number of characters in the file
  2.    The code counts number of words in the file
  3.    The code counts number of blank lines in the file
  4.    The code counts number of lines in the file
 Discuss Question
Answer: Option D. -> The code counts number of lines in the file

This program counts the number of lines in the file myfile.c by counting the character '`setminus`n' in that file.


Question 13.


Point out the error in the program?


#include<stdio.h>
/* Assume there is a file called 'file.c' in c:\tc directory. */
int main()
{
FILE *fp;
fp=fopen("c:\tc\file.c", "r");
if(!fp)
printf("Unable to open file.");
fclose(fp);
return 0;
}
  1.    No error, No output.
  2.    Program crashes at run time.
  3.    Output: Unable to open file.
  4.    None of above
 Discuss Question
Answer: Option C. -> Output: Unable to open file.

The path of file name must be given as "c: `setminus` `setminus` tc `setminus`file.c"



Question 14.


Point out the error in the program?


#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, "20", SEEK_SET);
fclose(fp);
return 0;
}
  1.    Error: unrecognised Keyword SEEK_SET
  2.    Error: fseek() long offset value
  3.    No error
  4.    None of above
 Discuss Question
Answer: Option B. -> Error: fseek() long offset value

Instead of "20" use 20L since fseek() need a long offset value.
Question 15.


Point out the error in the program?


#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
  1.    Error: suspicious char to in conversion in scanf()
  2.    Error: we may not get input for second scanf() statement
  3.    No error
  4.    None of above
 Discuss Question
Answer: Option B. -> Error: we may not get input for second scanf() statement


Question 16.


Point out the error in the program?


#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char;
FILE *fp;
fp=fopen("trial", "r");
if(!fp)
{
printf("Unable to open file");
exit(1);
}
fclose(fp);
return 0;
}
  1.    Error: in unsigned char statement
  2.    Error: unknown file pointer
  3.    No error
  4.    None of above
 Discuss Question
Answer: Option C. -> No error

This program tries to open the file trial.txt in read mode. If file not exists or unable to

read it prints "Unable to open file" and then terminate the program.

If file exists, it simply close the file and then terminates the program.


Question 17.


What will be the output of the program if value 25 given to scanf()?


#include<stdio.h>
int main()
{
int i;
printf("%d\n", scanf("%d", &i));
return 0;
}
  1.    25
  2.    2
  3.    1
  4.    5
 Discuss Question
Answer: Option C. -> 1

The scanf function returns the number of input is given.

printf("%d`setminus`n", scanf("%d", &i)); The scanf function returns the value 1(one).

Therefore, the output of the program is '1'.


Question 18.


What will be the output of the program ?


#include<stdio.h>
int main()
{
FILE *fp;
char ch, str[7];
fp=fopen("try.c", "r"); /* file 'try.c' contains "This is Nagpur" */
fseek(fp, 9L, SEEK_CUR);
fgets(str, 5, fp);
puts(str);
return 0;
}
  1.    agpur
  2.    gpur
  3.    Nagp
  4.    agpu
 Discuss Question
Answer: Option D. -> agpu


Question 19.


What will be the output of the program ?


#include<stdio.h>
int main()
{
int a=250;
printf("%1d\n", a);
return 0;
}
  1.    1250
  2.    2
  3.    50
  4.    250
 Discuss Question
Answer: Option D. -> 250

int a=250; The variable a is declared as an integer type and initialized to value 250.

printf("%1d`setminus`n", a); It prints the value of variable a.

Hence the output of the program is 250.


Question 20.



What will be the output of the program ?
#include<stdio.h>
int main()
{
printf("%%%%\n");
return 0;
}
  1.    %%%%%
  2.    %%
  3.    No output
  4.    Error
 Discuss Question
Answer: Option B. -> %%


Latest Videos

Latest Test Papers