File Input Output

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

What is the purpose of sprintf?

A. It prints the data into stdout
B. It writes the formatted data into a string
C. It writes the formatted data into a file
D. None of the mentioned
Answer: _________
Question 2:

Memory allocation using malloc() is done in . . . . . . . .

A. Static area
B. Stack area
C. Heap area
D. Both Stack & Heap area
Answer: _________
Question 3:

Which is true about isaplpha(c), where c is an int that can be represented as an unsigned? char or EOF.isalpha(c) returns

A. Non-zero if c is alphabetic
B. 0 if c is not alphabetic
C. Both Non-zero if c is alphabetic & 0 if c is not alphabetic
D. None of the mentioned
Answer: _________
Question 4:

For the function call time(), what type of parameter is accepted?

A. int
B. int *
C. time_t
D. time_t *
Answer: _________
Question 5:

fwrite() can be used only with files that are opened in binary mode.

A. true
B. false
Answer: _________
Question 6:

Which among the following is the odd one out?

A. printf
B. fprintf
C. putchar
D. scanf
Answer: _________
Question 7:

Output justification such as decimal point, numerical sign, trailing zeros or octal are specified.

A. specifier
B. flags
C. precision
D. decimal
Answer: _________
Question 8:

function fabs defined math.h header file takes the argument of type integer.

A. True
B. False
C. Depends on the implementation
D. Depends on the standard
Answer: _________
Question 9:

Which of the following is NOT a delimiter for an input in scanf?

A. Enter
B. Space
C. Tab
D. None of the mentioned
Answer: _________
Question 10:

Which is true about isupper(c), where c is an int that can be represented as an unsigned? char or EOF.isupper(c) returns

A. Non-zero if c is upper case
B. 0 if c is not upper case
C. Nothing
D. Both Non-zero if c is upper case & 0 if c is not upper case
Answer: _________
Question 11:

gets() function checks overflow run.

A. True
B. False
C. Depends on the standard
D. Undefined behaviour
Answer: _________
Question 12:

In linux, apart from including math header file, the program is successfully executed by which of the following?

A. cc filename.c
B. cc filename.c -lc
C. cc -math filename.c
D. cc -lm filename.c
Answer: _________
Question 13:

What is function srand(unsigned)?

A. Sets the seed for rand
B. Doesn't exist
C. Is an error
D. None of the mentioned
Answer: _________
Question 14:

What is the purpose of the C function? int ferror(FILE *fp)

A. They check for input errors
B. They check for output errors
C. They check for all types of errors
D. They check for error in accessing the file
Answer: _________
Question 15:

What if size is zero in the following C statement? realloc(ptr, size)

A. Allocate a memory location with zero length
B. Free the memory pointed to by ptr
C. Undefined behaviour
D. Doesn't do any reallocation of ptr i.e. no operation
Answer: _________
Question 16:

Which one of the following is correct syntax for opening a file.

A. FILE *fopen(const *filename, const char *mode)
B. FILE *fopen(const *filename)
C. FILE *open(const *filename, const char *mode)
D. FILE open(const*filename)
Answer: _________
Question 17:

What will cos(x) return?

A. sine of x where x is in radians
B. sine of x where x is in degree
C. cosine of x where x is in radians
D. cosine of x where x is in degree
Answer: _________
Question 18:

Choose the right statement for fscanf() and scanf()

A. fscanf() can read from standard input whereas scanf() specifies a stream from which to read
B. fscanf() can specifies a stream from which to read whereas scanf() can read only from standard input
C. fscanf() and scanf() has no difference in their functions
D. fscanf() and scanf() can read from specified stream
Answer: _________
Question 19:

What is the function of the mode ' w+'?

A. create text file for writing, discard previous contents if any
B. create text file for update, discard previous contents if any
C. create text file for writing, do not discard previous contents if any
D. create text file for update, do not discard previous contents if any
Answer: _________
Question 20:

gets() does the following when it reads from stdin.

A. Deletes the 't'
B. Puts adds it.
C. Deletes the terminating 'n'
D. Nothing
Answer: _________
Question 21:

What is the qualifying input for the type specifier G?

A. floating point numbers
B. floating point numbers in exponential format
C. floating point numbers in the shorter of exponential format
D. not a type specifier
Answer: _________
Question 22:

The function fprintf is used in the program ...........

A. When too many printf calls have been used in the program.
B. In place of printf, as it uses more memory.
C. When the output is to be printed on to a file.
D. When the type of the variables to be printed are not known.
Answer: _________
Question 23:

Choose the correct difference between getc() and fgetc().

A. If it is not a macro, it may evaluate stream more than once
B. if it is amacro, it may not evaluate stream more than once
C. if it is a macro, it may evaluate stream more than once
D. no difference between fgetc() and getc()
Answer: _________
Question 24:

. . . . . . . . is an optional argument that gives the maximum number of characters to be read.

A. modifiers
B. width
C. precision
D. length
Answer: _________
Question 25:

If the conversion characters of int d, i, o, u and x are preceded by h, it indicates?

A. A pointer to int
B. A pointer to short
C. A pointer to long
D. A pointer to char
Answer: _________
Question 26:

Which of the following function compares 2 strings with case-insensitively?

A. strcmp(s, t)
B. strcmpcase(s, t)
C. strcasecmp(s, t)
D. strchr(s, t)
Answer: _________
Question 27:

fflush(NULL) flushes all . . . . . . . .

A. input streams
B. output streams
C. previous contents
D. appended text
Answer: _________
Question 28:

What will fopen will return, if there is any error while opening a file?

A. Nothing
B. EOF
C. NULL
D. Depends on compiler
Answer: _________
Question 29:

The parameter control string in the printf () is a C String that contains text to be . . . . . . . .

A. taken from a standard output device
B. written on to the standard output device
C. received from the standard output device
D. nothing can be said
Answer: _________
Question 30:

The syntax to print a % using printf statement can be done by . . . . . . . .

A. %
B. \%
C. '%'
D. %%
Answer: _________
Question 31:

The conversion characters d, i, o, u, and x may be preceded by h in scanf() to indicate?

A. A pointer to short
B. A pointer to long
C. Nothing
D. Error
Answer: _________
Question 32:

The maximum number of characters to be printed is specified by . . . . . . . .

A. precision
B. width
C. length
D. flags
Answer: _________
Question 33:

In function free(p), p is a . . . . . . . .

A. int
B. pointer returned by malloc()
C. pointer returned by calloc()
D. pointer returned by malloc() & calloc()
Answer: _________
Question 34:

What is the difference in the ASCII value of capital and non-capital of the same letter is?

A. 1
B. 16
C. 32
D. Depends with compiler
Answer: _________
Question 35:

Select the right explanation for the following C code snippet. int fgetpos(FILE *stream, fpos_t *s)

A. records the current position in stream in *s
B. sets the file position for stream in *s
C. positions stream at the position recorded in *s
D. reads from stream into the array ptr
Answer: _________
Question 36:

Which of the following library function is not case-sensitive?

A. toupper()
B. tolower()
C. isdigit()
D. all of the mentioned
Answer: _________
Question 37:

What does the following C code snippet mean? int ungetc(int c, FILE *stream)

A. pushes c back onto a stream
B. deletes c from the stream
C. reads frequency of c in stream
D. no action is taken by the command
Answer: _________
Question 38:

Which is the best way to generate numbers between 0 to 99?

A. rand()-100
B. rand()%100
C. rand(100)
D. srand(100)
Answer: _________
Question 39:

What error will be generated on using incorrect specifier for the datatype being read?

A. compile error
B. run-time error
C. logical error
D. no error
Answer: _________
Question 40:

In C language, FILE is of which data type?

A. int
B. char *
C. struct
D. None of the mentioned
Answer: _________
Question 41:

Which types of input are accepted in toupper(c)?

A. char
B. char *
C. float
D. Both char and char *
Answer: _________
Question 42:

what is the return value of fputs()?

A. EOF if an error occurs
B. Non-negative if no error
C. EOF if an error occurs & Non-negative if no error
D. None of the mentioned
Answer: _________
Question 43:

What will be the output of the following C statement? int sscanf(char *string, char *format, arg1, arg2, ...)

A. Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc
B. The arguments arg1,arg2 etc must be pointers
C. Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc, those arguments arg1,arg2 etc must be pointers
D. None of the mentioned
Answer: _________
Question 44:

stderr is similar to?

A. stdin
B. stdout
C. Both stdout and stdin
D. None of the mentioned
E. stdin
F. stdout
G. both stdout and stdin
H. none of the mentioned
Answer: _________
Question 45:

What error is generated on placing an address operator with a variable in the printf statement?

A. compile error
B. run-time error
C. logical error
D. no error
Answer: _________
Question 46:

What will sin(x) returns?

A. sine of x where x is in radians
B. sine of x where x is in degree
C. cosine of x where x is in radians
D. cosine of x where x is in degree
Answer: _________
Question 47:

what is the function of fputs()?

A. read a line from a file
B. read a character from a file
C. write a character to a file
D. write a line to a file
Answer: _________
Question 48:

rand() and srand() functions are used . . . . . . . .

A. To find sqrt
B. For and operations
C. For or operations
D. To generate random numbers
Answer: _________
Question 49:

. . . . . . . . is used to define the type and the interpretation of the value of the corresponding argument.

A. precision
B. specifiers
C. flags
D. decimal
Answer: _________
Question 50:

What is FILE reserved word?

A. A structure tag declared in stdio.h
B. One of the basic data types in c
C. Pointer to the structure defined in stdio.h
D. It is a type name defined in stdio.h
Answer: _________
Question 51:

Each call of va_arg . . . . . . . .

A. Returns one argument
B. Steps va_list variable to the next
C. Returns one argument & Steps va_list variable to the next
D. None of the mentioned
Answer: _________
Question 52:

setvbuf() and setbuf() function controls buffering for the stream.

A. true
B. false
Answer: _________
Question 53:

fputs() function writes a string to a file that only ends with a newline.

A. True
B. False
C. Depends on the standard
D. Depends on the compiler
Answer: _________
Question 54:

. . . . . . . . removes the named file, so that a subsequent attempt to open it will fail.

A. remove(const *filename)
B. remove(filename)
C. remove()
D. fclose(filename)
Answer: _________
Question 55:

Escape sequences are prefixed with . . . . . . . .

A. %
B. /
C. "
D. None of the mentioned
Answer: _________
Question 56:

What is the default return-type of getchar()?

A. char
B. int
C. char *
D. reading character doesn't require a return-type
Answer: _________
Question 57:

ungetc() may be used with . . . . . . . .

A. scanf
B. getc
C. getchar
D. all of the mentioned
Answer: _________
Question 58:

stdout, stdin and stderr are . . . . . . . .

A. File pointers
B. File descriptors
C. Streams
D. Structure
Answer: _________
Question 59:

Which of the following causes an error?

A. Trying to read a file that doesn't exist
B. Inability to write data in a file
C. Failure to allocate memory with the help of malloc
D. All of the mentioned
Answer: _________
Question 60:

Which header file includes a function for variable number of arguments?

A. stdlib.h
B. stdarg.h
C. ctype.h
D. both stdlib.h and stdarg.h
Answer: _________
Question 61:

fputs() adds newline character.

A. True
B. False
C. Depends on the standard
D. Undefined behaviour
Answer: _________
Question 62:

For binary files, a . . . . . . . . must be appended to the mode string.

A. Nothing
B. "b"
C. "binary"
D. "01"
Answer: _________
Question 63:

The standard header . . . . . . . . is used for variable list arguments (...) in C.

A. <stdio.h >
B. <stdlib.h>
C. <math.h>
D. <stdarg.h>
Answer: _________
Question 64:

What specifies the minimum number of characters to print after being padded with zeros or blank spaces?

A. flags
B. length
C. width
D. precision
Answer: _________
Question 65:

What symbol is used to Left-justify within the data given field width?

A. -(minus sign)
B. +(plus sign)
C. #
D. 0
Answer: _________
Question 66:

The functions vprintf(), vfprintf(), and vsprintf() are not equivalent to the corresponding printf() functions except the variable argument list.

A. true
B. false
Answer: _________
Question 67:

Which is true about isalnum(c), where c is an int that can be represented as an unsigned? char or EOF.isalnum(c) returns

A. Non-zero if isalpha(c) or isdigit(c)
B. 0 if not isalpha(c) or not isdigit(c)
C. Both Non-zero if isalpha(c) or isdigit(c) & 0 if not isalpha(c) or not isdigit(c)
D. None of the mentioned
Answer: _________
Question 68:

What type of return-type used in String operations?

A. void only
B. void and (char *) only
C. void and int only
D. void, int and (char *) only
Answer: _________
Question 69:

The function . . . . . . . . obtains a block of memory dynamically.

A. calloc
B. malloc
C. both calloc & malloc
D. free
Answer: _________
Question 70:

What happens when we use the following C statement?

A. The diagnostic output is directly displayed in the output
B. The diagnostic output is pipelined to the output file
C. The line which caused error is compiled again
D. The program is immediately aborted
Answer: _________
Question 71:

Explain the format string "%5d%s %c"

A. five characters as a decimal integer, then reads the remaining as a string and then scans the first non-whitespace character
B. compile error
C. run-time error
D. read first five characters as a decimal and ignore the rest
Answer: _________
Question 72:

What is the difference between %e and %g?

A. %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional
B. %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument
C. No differences
D. Depends on the standard
Answer: _________
Question 73:

Strcat() function adds null character.

A. Only if there is space
B. Always
C. Depends on the standard
D. Depends on the compiler
Answer: _________
Question 74:

If the mode includes b after the initial letter, what does it indicates?

A. text file
B. big text file
C. binary file
D. blueprint text
Answer: _________
Question 75:

A fatal error will be generated if the format string is ended with a white space character.

A. true
B. false
Answer: _________
Question 76:

Which of the following mode argument is used to truncate?

A. a
B. f
C. w
D. t
Answer: _________
Question 77:

What does the following command line signify? prog1|prog2

A. It runs prog1 first, prog2 second
B. It runs prog2 first, prog1 second
C. It runs both the programs, pipes output of prog1 to input of prog2
D. It runs both the programs, pipes output of prog2 to input of prog1
Answer: _________
Question 78:

Which function has a return type as char pointer?

A. getline
B. fputs
C. fgets
D. all of the mentioned
Answer: _________
Question 79:

What is the syntax of ungetc()?

A. void ungetc(int c, FILE *fp)
B. int ungetc(int c, FILE *fp)
C. int ungetc(String c, FILE *fp)
D. int getc(int c, FILE *fp)
Answer: _________
Question 80:

scanf() is a predefined function in. . . . . . . .header file.

A. stdlib. h
B. ctype. h
C. stdio. h
D. stdarg. h
Answer: _________
Question 81:

Which type of files can't be opened using fopen()?

A. .txt
B. .bin
C. .c
D. none of the mentioned
Answer: _________
Question 82:

What will be the output of the following C function when EOF returns? int fputs(char *line, FILE *fp)

A. 'a' character of array line is encountered
B. 'n' character in array line is encountered
C. 't' character in array line is encountered
D. When an error occurs
Answer: _________
Question 83:

A conversion specification %7.4f means . . . . . . . .

A. print a floating point value of maximum 7 digits where 4 digits are allotted for the digits after the decimal point
B. print a floating point value of maximum 4 digits where 7digits are allotted for the digits after the decimal point
C. print a floating point value of maximum 7 digits
D. print a floating point value of minimum 7 digits where 4 digits are allotted for the digits after the decimal point
Answer: _________
Question 84:

puts() function adds newline character.

A. True
B. False
C. Depends on the standard
D. Undefined behaviour
Answer: _________
Question 85:

The . . . . . . . . function reads atmost one less than the number of characters specified by size from the given stream and it is stored in the string str.

A. fget()
B. fgets()
C. fput()
D. fputs()
Answer: _________
Question 86:

What does tmpfile() returns when it could not create the file?

A. stream and NULL
B. only stream
C. only NULL
D. does not return anything
Answer: _________
Question 87:

Within main, return expr statement is equivalent to . . . . . . . .

A. abort(expr)
B. exit(expr)
C. ferror(expr)
D. none of the mentioned
Answer: _________
Question 88:

ungetc() can be used only with getc().

A. true
B. false
C. depends on the standard
D. depends on the platform
Answer: _________
Question 89:

calloc() returns storage that is initialized to.

A. Zero
B. Null
C. Nothing
D. One
Answer: _________
Question 90:

puts() does the following when it writes to stdout.

A. Deletes everything
B. Adds 't' to the line written
C. Deletes the terminating 'n'
D. Adds 'n' to the line written
Answer: _________
Question 91:

Which of the following statement is true?

A. The symbolic constant EOF is defined in <stdio.h>
B. The value is -1
C. The symbolic constant EOF is defined in <stdio.h> & value is -1
D. Only value is -1
Answer: _________
Question 92:

Control string specifies the type and format of the data that has to be obtained from the keyboard.

A. true
B. false
Answer: _________
Question 93:

What are the first and second arguments of fopen?

A. A character string containing the name of the file & the second argument is the mode
B. A character string containing the name of the user & the second argument is the mode
C. A character string containing file pointer & the second argument is the mode
D. None of the mentioned
Answer: _________
Question 94:

In a variable length argument function, the declaration "..." can . . . . . . . .

A. Appear anywhere in the function declaration
B. Only appear at the end of an argument list
C. Nothing
D. None of the mentioned
Answer: _________
Question 95:

Which function is used to write a character to a file in C?

A. putc()
B. writechar()
C. putchar()
D. fileputchar()
Answer: _________
Question 96:

What happens if you try to open a file in 'r' mode that doesn't exist in C?

A. A new file is created
B. An error occurs, and the file remains unchanged
C. The program terminates
D. The file is deleted
Answer: _________
Question 97:

How do you read a string from a file in C?

A. fscanf()
B. readstring()
C. getline()
D. fgets()
Answer: _________
Question 98:

What does the 'remove' function in C do?

A. Deletes a file
B. Renames a file
C. Closes a file
D. Appends data to a file
Answer: _________
Question 99:

In C, what is the purpose of the 'fflush' function?

A. To flush the standard input buffer
B. To flush the standard output buffer
C. To close a file
D. To check if a file exists
Answer: _________
Question 100:

Which function is used to create a new directory in C?

A. createdir()
B. makedir()
C. mkdir()
D. newfolder()
Answer: _________
Question 101:

How do you write an integer to a file in C?

A. putint()
B. fprintf()
C. writeint()
D. filewriteint()
Answer: _________
Question 102:

What is the return value of 'putc' if it fails to write a character to a file in C?

A. 0
B. 1
C. -1
D. EOF
Answer: _________
Question 103:

Which function is used to read and write data in binary mode in C?

A. fread()
B. fwritedata()
C. readbinary()
D. writebinary()
Answer: _________
Question 104:

What is the purpose of the 'fileno' function in C?

A. To find the file number associated with a file
B. To check if a file exists
C. To get the file's size
D. To close a file
Answer: _________
Question 105:

Which function is used to move the file pointer to a specific position in a file?

A. fseek()
B. movefile()
C. setposition()
D. fileseek()
Answer: _________
Question 106:

What is the purpose of the 'rewind' function in C?

A. To close the file
B. To reset the file pointer to the beginning
C. To delete the file
D. To check if the file is empty
Answer: _________
Question 107:

Which function is used to read a line of text from a file in C?

A. readtext()
B. getline()
C. fgets()
D. readline()
Answer: _________
Question 108:

What is the difference between 'r+' and 'w+' modes when opening a file in C?

A. 'r+' is for reading and writing, 'w+' is for reading only
B. 'r+' is for reading and writing, 'w+' is for writing only, creating a new file
C. 'r+' is for reading and writing, 'w+' is for writing only, overwriting an existing file
D. 'r+' is for reading only, 'w+' is for reading and writing, creating a new file
Answer: _________
Question 109:

Which function is used to delete a file in C?

A. deletefile()
B. remove()
C. erasefile()
D. delete()
Answer: _________
Question 110:

What does the 'fread' function in C do?

A. Reads binary data from a file
B. Reads formatted data from a file
C. Reads a specific line from a file
D. Reads a character from a file
Answer: _________
Question 111:

Which function is used to rename a file in C?

A. rename()
B. changename()
C. movefile()
D. setfilename()
Answer: _________
Question 112:

In C, what does the 'feof' function return if the end of the file is reached?

A. 0
B. 1
C. -1
D. EOF
Answer: _________
Question 113:

How do you check if a file exists in C?

A. Use the 'fileexist' function
B. Check the return value of fopen()
C. Use the 'filestatus' variable
D. Use the 'fileopen' function
Answer: _________
Question 114:

What is the purpose of the 'ftell' function in C?

A. To find the current position of the file pointer
B. To find the total number of bytes in a file
C. To check if a file is open
D. To find the file's size
Answer: _________
Question 115:

Choose the correct description for control string %-+7.2f.

A. - means display the sign, + means left justify, 7 specifies the width and 2 specifies the precision
B. - means left justify, + means display the sign, 7 specifies the width and 2 specifies the precision
C. - means display the sign, + means left justify, 7 specifies the precision and 2 specifies the width
D. - means left justify, + means display the sign, 7 specifies the precision and 2 specifies the width
Answer: _________
Question 116:

ungetc() is used . . . . . . . .

A. to get a char
B. to get an int
C. to push a character back to file
D. nothing
Answer: _________
Question 117:

What error will generate if the read and write parameters are not separated by commas?

A. run-time error
B. compile error
C. logical error
D. no error
Answer: _________
Question 118:

gets() and puts() operate on . . . . . . . .

A. stdin and stdout
B. files
C. stderr
D. nothing
Answer: _________
Question 119:

Only . . . . . . . . character of pushback is guaranteed per file when ungetc is used.

A. Two
B. One
C. Many
D. Zero
Answer: _________
Question 120:

The following C expression can be substituted for? if (isalpha(c) && isdigit(c))

A. if (isalnum(c))
B. if (isalphanum(c))
C. if (isalphanumeric(c))
D. none of the mentioned
Answer: _________
Question 121:

Which is not true about function tolower?

A. The function tolower is defined in <ctype.h>
B. Converts an uppercase letter to lowercase
C. Returns other characters untouched
D. None of the mentioned
Answer: _________
Question 122:

putchar(c) function/macro always outputs character c to the . . . . . . . .

A. screen
B. standard output
C. depends on the compiler
D. depends on the standard
Answer: _________
Question 123:

What is the return type of rand() function?

A. short
B. int
C. long
D. double
Answer: _________
Question 124:

What are the Properties of the first argument of a printf() functions?

A. It is defined by a user
B. It keeps the record of the types of arguments that will follow
C. There may no be first argument
D. None of the mentioned
Answer: _________
Question 125:

The syntax of fgets is char *fgets(char *line, int maxline, FILE *fp). Which is true for fgets?

A. Returns line on success
B. On end of file or error it returns NULL
C. Nothing
D. Both returns line on success & On end of file or error it returns NULL
Answer: _________
Question 126:

What does the following C code snippet mean? char *gets(char *s)

A. reads the next input line into the array s
B. writes the line into the array s
C. reads the next input character into the array s
D. write a character into the array
Answer: _________
Question 127:

Which functions is declared in ?

A. fseek()
B. ftell()
C. ferror()
D. fsetpos()
Answer: _________
Question 128:

What does scanf() function return?

A. Number of successfully matched and assigned input items
B. Nothing
C. Number of characters properly printed
D. Error
Answer: _________
Question 129:

What is the use of symbol * in the control string as shown [=%[*][width] [modifiers] type=]?

A. * is optional and used when the data should be read from the stream but ignored
B. * is not optional, used to read data from the stream but it is not ignored
C. * is not optional, it is used to read data stream but ignored
D. * is optional and used to read data from stream but it is not ignored
Answer: _________
Question 130:

For a typical program, the input is taken using . . . . . . . .

A. scanf
B. Files
C. Command-line
D. All of the mentioned
Answer: _________
Question 131:

What is the return value of putchar()?

A. The character written
B. EOF if an error occurs
C. Nothing
D. Both character written & EOF if an error occurs
Answer: _________
Question 132:

In C, which library is used for file operations such as reading and writing files?

A. stdio.h
B. iostream.h
C. fileio.h
D. files.h
Answer: _________
Question 133:

Which function is used to open a file in C for writing?

A. fopen()
B. open()
C. writefile()
D. createfile()
Answer: _________
Question 134:

What does 'FILE' represent in C when working with files?

A. A built-in data type for files
B. A file descriptor
C. A file pointer
D. A file structure
Answer: _________
Question 135:

How do you check if a file was opened successfully in C?

A. Use the 'filestatus' variable
B. Check the return value of fopen()
C. Use the 'fileopen' function
D. Check the file's size
Answer: _________
Question 136:

Which function is used to write data to a file in C?

A. fwrite()
B. writefile()
C. filewrite()
D. putfile()
Answer: _________
Question 137:

What is the difference between 'r' and 'w' modes when opening a file in C?

A. 'r' is for read-only and 'w' is for write-only
B. 'r' is for reading and 'w' is for reading and writing
C. 'r' is for read-only and 'w' is for write-only, creating a new file
D. 'r' is for reading and 'w' is for writing, overwriting an existing file
Answer: _________
Question 138:

How do you read a character from a file in C?

A. getc()
B. readchar()
C. read()
D. getchar()
Answer: _________
Question 139:

What is the purpose of the 'fprintf' function in C?

A. To format and write data to a file
B. To read data from a file
C. To open a file
D. To close a file
Answer: _________
Question 140:

Which function is used to close a file in C?

A. closefile()
B. fclose()
C. endfile()
D. fileclose()
Answer: _________
Question 141:

In C, what is the function of the 'feof' function?

A. To check if the file has reached the end
B. To find the size of a file
C. To check if the file is open
D. To check if the file exists
Answer: _________
Question 142:

Which of the following statements about stdout and stderr are true?

A. Same
B. Both connected to screen always
C. Both connected to screen by default
D. stdout is line buffered but stderr is unbuffered
Answer: _________
Question 143:

On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to.

A. NULL
B. Other dynamically allocated memory
C. The same deallocated memory location
D. It points back to the location it was initialized with
Answer: _________
Question 144:

void * malloc(size_t n) returns?

A. Pointer to n bytes of uninitialized storage
B. NULL if the request can be satisfied
C. Nothing
D. None of the mentioned
Answer: _________
Question 145:

Which of the following represents the function for scanf()?

A. void scanf(char *format, ...)
B. int scanf(char *format, ...)
C. char scanf(int format, ...)
D. char *scanf(char *format, ...)
Answer: _________
Question 146:

Which of the following can be used for random number generation?

A. random()
B. rnd()
C. rndm()
D. none of the mentioned
Answer: _________
Question 147:

For floating point numbers, the precision flag specifies the number of decimal places to be printed. When no precision modifier is specified, printf() prints . . . . . . . .

A. six decimal positions
B. five decimal positions
C. four decimal positions
D. three decimal positions
Answer: _________
Question 148:

Which of the following cannot be used with ungetc()?

A. scanf
B. getc
C. getchar
D. printf
Answer: _________
Question 149:

Which character of pushback is guaranteed per file?

A. True
B. False
C. Depends on the compiler
D. Depends on the platform
Answer: _________
Question 150:

String operation such as strcat(s, t), strcmp(s, t), strcpy(s, t) and strlen(s) heavily rely upon.

A. Presence of NULL character
B. Presence of new-line character
C. Presence of any escape sequence
D. None of the mentioned
Answer: _________
Question 151:

Which function will return the current file position for stream?

A. fgetpos()
B. fseek()
C. ftell()
D. fsetpos()
Answer: _________
Question 152:

When a C program is started, O.S environment is responsible for opening file and providing pointer for that file?

A. Standard input
B. Standard output
C. Standard error
D. All of the mentioned
Answer: _________
Question 153:

What is the function of FILE *tmpfile(void)?

A. creates a temporary file of mode "wb+"
B. creates a temporary file of mode "wb"
C. creates a temporary file of mode " w"
D. creates a temporary file of mode "w+"
Answer: _________
Question 154:

What happens when zero flag is used with left justification?

A. data is padded with zeros
B. zero flag is ignored
C. data is padded with blank spaces
D. will give error
Answer: _________
Question 155:

EOF is an integer type defined in stdio. hand has a value . . . . . . . .

A. 1
B. 0
C. NULL
D. - 1
Answer: _________
Question 156:

What is the size of array "line" used in fgets(line, maxline, *fp) function?

A. maxline - 1
B. maxline
C. maxline + 1
D. Size is dynamic
Answer: _________
Question 157:

What will be the output of the following C statement? int ungetc(int c, FILE *fp)

A. Either c or EOF for an error
B. Nothing
C. fp
D. None of the mentioned
Answer: _________
Question 158:

What type of inputs are accepted by mathematical functions?

A. short
B. int
C. float
D. double
Answer: _________
Question 159:

Which of the following will return a result most quickly for searching a given key?

A. Unsorted Array
B. Sorted Array
C. Sorted linked list
D. Binary Search Tree
Answer: _________
Question 160:

Which of the following macro extracts an argument from the variable argument list (ie ellipsis) and advance the pointer to the next argument?

A. va_list
B. va_arg
C. va_end
D. va_start
Answer: _________
Question 161:

calloc() initialize memory with all bits set to zero.

A. True
B. False
C. Depends on the compiler
D. Depends on the standard
Answer: _________
Question 162:

The statement prog < infile causes . . . . . . . .

A. prog to read characters from infile
B. prog to write characters to infile
C. infile to read characters from prog instead
D. nothing
Answer: _________
Question 163:

What is the use of getchar()?

A. The next input character each time it is called
B. EOF when it encounters end of file
C. The next input character each time it is called EOF when it encounters end of file
D. None of the mentioned
Answer: _________
Question 164:

Which of the following data-types are promoted when used as a parameter for an ellipsis?

A. char
B. short
C. int
D. none of the mentioned
Answer: _________
Question 165:

What is the value of EOF?

A. -1
B. 0
C. 1
D. 10
Answer: _________
Question 166:

Which of these is a correct way to generate numbers between 0 to 1(inclusive) randomly?

A. rand() / RAND_MAX
B. rand() % 2
C. rand(0, 1)
D. none of the mentioned
Answer: _________
Question 167:

log(x) function defined in math.h header file is . . . . . . . .

A. Natural base logarithm
B. Logarithm to the base 2
C. Logarithm to the base 10
D. None of the mentioned
Answer: _________
Question 168:

What is the return value of getc()?

A. The next character from the stream is not referred by file pointer
B. EOF for end of file or error
C. Nothing
D. None of the mentioned
Answer: _________
Question 169:

What action is carried out by scanf if a user enters any blank spaces, tabs, and newlines?

A. consider as input
B. ignores it
C. produces error
D. nothing can be said
Answer: _________
Question 170:

Which of the following will return a non-zero value when checked with isspace(c)?

A. blank
B. newline
C. return
D. all of the mentioned
Answer: _________
Question 171:

If by mistake you specify more number of arguments, the excess arguments will . . . . . . . .

A. be ignored
B. produce compile error
C. produce run-time error
D. produce logical error
Answer: _________
Question 172:

What is the purpose of va_end?

A. Cleanup is necessary
B. Must be called before the program returns
C. Cleanup is necessary & Must be called before the program returns
D. None of the mentioned
Answer: _________
Question 173:

What is the meaning of the following C statement? printf(“%10s”, state)

A. 10 spaces before the string state is printed
B. Print empty spaces if the string state is less than 10 characters
C. Print the last 10 characters of the string
D. None of the mentioned
Answer: _________
Question 174:

What will be the output of the following C code? #include <stdio.h>
int main()
{
short int i

scanf("%*d", &i)

printf("%hd", i)

return 0

}

A. Compilation error
B. Somegarbage value
C. Whatever user types
D. Depends on the standard
Answer: _________
Question 175:

What does the following segment of C code do? fprintf(fp, "Copying!")

A. It writes "Copying!" into the file pointed by fp
B. It reads "Copying!" from the file and prints on display
C. It writes as well as reads "Copying!" to and from the file and prints it
D. None of the mentioned
Answer: _________
Question 176:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char *s = "myworld"

int i = 9

printf("%*s", i, s)

}

A. myworld
B. myworld(note: spaces to the left of myworld)
C. myworld (note:followed by two spaces after myworld)
D. Undefined
Answer: _________
Question 177:

What will be the output of the following C statement? fprintf(stderr, "error: could not open filen")

A. The diagnostic output is directly displayed in the output
B. The diagnostic output is pipelined to the output file
C. The line which caused error is compiled again
D. The program is immediately aborted
Answer: _________
Question 178:

Which of the following doesn't require an & for the input in scanf()?

A. char name[10]
B. int name[10]
C. float name[10]
D. all of the mentioned
Answer: _________
Question 179:

Which of the following is the correct syntax for calling function ungetc? Assume int c and FILE *fp

A. ungetc(c,*fp)
B. ungetc(c, fp)
C. ungetc(fp, c)
D. ungetc(*fp,c)
Answer: _________
Question 180:

If the user enters 1 s 3.2, what value will be returned by the scanf()? scanf("%d %f %c", &a, &b, &c)

A. 1
B. 2
C. 3
D. no return value
Answer: _________
Question 181:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char str[10] = "hello"

char *p = strrchr(str, 'l')

printf("%c
", *(++p))

}

A. l
B. o
C. e
D. Compilation error
Answer: _________
Question 182:

What will be the output of the following C code? #include <stdio.h>
int main()
{
FILE *fp = stdin

int n

fprintf(fp, "%d", 45)

}

A. Compilation error
B. 45
C. Nothing
D. Depends on the standard
Answer: _________
Question 183:

What will be the output of the following C code? #include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world"

char *str1 = "hello, world"

if (strcmp(str, str1))
printf("equal")

else
printf("unequal")

}

A. equal
B. unequal
C. Compilation error
D. Depends on the compiler
Answer: _________
Question 184:

What will be the output of the following C code? #include <stdio.h>
int main()
{
int n

scanf("%d", n)

printf("%d
", n)

return 0

}

A. Compilation error
B. Undefined behavior
C. Whatever user types
D. Depends on the standard
Answer: _________
Question 185:

Which of the following is not a valid mathematical function?

A. frexp(x)
B. atan2(x,y)
C. srand(x)
D. fmod(x)
Answer: _________
Question 186:

What will be the output of the following C code? #include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world"

char str1[9]

strncpy(str1, str, 9)

printf("%s %d", str1, strlen(str1))

}

A. hello, world 11
B. hello, wor 9
C. Undefined behaviour
D. Compilation error
Answer: _________
Question 187:

What will be the output of the following C code if following commands are used to run and if myfile does not exist? gcc -o test test.c
./test > myfile
#include <stdio.h>
int main(int argc, char **argv)
{
char c = 'd'

putchar(c)

printf(" %d
", argc)

}

A. d 2 in myfile
B. d 1 in myfile
C. Depends on the system
D. Depends on the standard
Answer: _________
Question 188:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char c = '�'

putchar(c)

}

A. Compile time error
B. Nothing
C. 0
D. Undefined behaviour
Answer: _________
Question 189:

In the below C program, every time program is run different numbers are generated. #include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%d
", rand())

return 0

}

A. True
B. False
C. Depends on the platform
D. Depends on the compiler
Answer: _________
Question 190:

What does the ungetc function return for the following C expression? ungetc(c, fp)

//where declarations are int c and FILE *fp

A. It returns character c
B. It returns EOF for an error
C. Both returns character c and returns EOF for an error
D. Either returns character c or returns EOF for an error
Answer: _________
Question 191:

If the user enters 1 3.2 s, what value will be returned by the scanf()? scanf("%d %f %c", &s1, &s2, &s3)

A. 1
B. 2
C. 3
D. No return value
Answer: _________
Question 192:

Why do we write (int *) before malloc? int *ip = (int *)malloc(sizeof(int))

A. It is for the syntax correctness
B. It is for the type-casting
C. It is to inform malloc function about the data-type expected
D. None of the mentioned
Answer: _________
Question 193:

What will be the output of the following C code? #include <stdio.h>
int main()
{
FILE *fp

char c

int n = 0

fp = fopen("newfile1.txt", "r")

while (!feof(fp))
{
c = getc(fp)

putc(c, stdout)

}
}

A. Compilation error
B. Prints to the screen content of newfile1.txt completely
C. Prints to the screen some contents of newfile1.txt
D. None of the mentioned
Answer: _________
Question 194:

What will be the output for the given code. printf("
The number is %07d",1212)

A. The number is 0001212
B. The number is 1212
C. The number is 071212
D. The number is 1212000
Answer: _________
Question 195:

Which of the following snippet will effectively generate random numbers?

A. rand()
B. rand(10)
C. rand(time(NULL))
D. all of the mentioned
Answer: _________
Question 196:

What will be the output of the following C code? #include <stdio.h>
#include <stdarg.h>
int f(...)

int main()
{
char c = 97

f(c)

return 0

}
int f(...)
{
va_list li

char c = va_arg(li, char)

printf("%c
", c)

}

A. Compile time error
B. Undefined behaviour
C. 97
D. a
Answer: _________
Question 197:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello, world"

char str1[15] = "hello wo 9"

strcpy(str, str1)

printf("%s", str1)

}

A. Compilation error
B. Segmentation Fault
C. hello, world
D. hello, wo 9
Answer: _________
Question 198:

What does the C statement given below says? scanf("%7s",ch)

A. read string with minimum 7 characters.
B. read string with maximum 7 characters
C. read string exactly to 7 characters
D. read string with any number of characters
Answer: _________
Question 199:

Which is the correct way to generate numbers between minimum and maximum(inclusive)?

A. minimum + (rand() % (maximum - minimum))
B. minimum + (rand() % (maximum - minimum + 1))
C. minimum * (rand() % (maximum - minimum))
D. minimum - (rand() % (maximum + minimum))
Answer: _________
Question 200:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char str[10] = "hello"

char *str1 = "world"

strncat(str, str1, 9)

printf("%s", str)

}

A. helloworld
B. Undefined behaviour
C. helloworl
D. hellowor
Answer: _________
Question 201:

What will be the value of var for the following C statement? var = strcmp("Hello", "World")

A. -1
B. 0
C. 1
D. strcmp has void return-type
Answer: _________
Question 202:

What will be the output of the following C code? #include <stdio.h>
#include <ctype.h>
int main()
{
char c = 't'
printf("is :%c
", tolower('A'))
}

A. A
B. a
C. Non-zero number
D. Zero
Answer: _________
Question 203:

Which mathematical function among the following does NOT require int parameters?

A. div(x, y)
B. srand(x)
C. sqrt(x)
D. all of the mentioned
Answer: _________
Question 204:

Which pre-defined function returns a pointer to the last occurence of a character in a string?

A. strchr(s, c)
B. strrchr(s, c)
C. strlchr(s, c)
D. strfchr(s, c)
Answer: _________
Question 205:

Select the correct value of i from given options i=scanf("%d %d", &a, &b)

A. 1
B. 2
C. 3
D. No value assigned
Answer: _________
Question 206:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char str[11] = "hello"
char *str1 = "world"
strcat(str, str1)
printf("%s %d", str, str[10])
}

A. helloworld 0
B. helloworld anyvalue
C. worldhello 0
D. Segmentation fault/code crash
Answer: _________
Question 207:

What will the given code result is printf("
you are"awesome " ")

A. compile error
B. run-time error
C. you are "awesome"
D. you are awesome
Answer: _________
Question 208:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello, world
"
printf("%d", strlen(str))
}

A. Compilation error
B. Undefined behaviour
C. 13
D. 11
Answer: _________
Question 209:

What is the meaning of the following C statement? scanf("%[^
]s", ch)

A. read all character except new line
B. read all characters
C. read only new line character
D. syntax error
Answer: _________
Question 210:

What will be the output of the following C code? #include <stdio.h>
int main()
{
FILE *fp = stdout
int n
fprintf(fp, "%d ", 45)
fprintf(stderr, "%d ", 65)
return 0
}

A. 45 65
B. 65 45
C. 65
D. Compilation error
Answer: _________
Question 211:

What will be the output of the following C code? #include <stdio.h>
int main()
{
printf("%d
", srand(9000))
return 0
}

A. Compile time error
B. An integer in the range 0 to 9000
C. A float in the range 0 to 1
D. A double in the range 0 to 9000
Answer: _________
Question 212:

What will be the output of the following C code? #include <stdio.h>
int main()
{
FILE *fp = stdout
stderr = fp
fprintf(stderr, "%s", "hello")
}

A. Compilation error
B. hello
C. Undefined behaviour
D. Depends on the standard
Answer: _________
Question 213:

Which of the following function can be used to terminate the main function from another function safely?

A. return(expr)
B. exit(expr)
C. abort()
D. both exit(expr) and abort()
Answer: _________
Question 214:

What will be the output of the following C code? #include <stdio.h>
int f(char chr, ...)
int main()
{
char c = 97
f(c)
return 0
}
int f(char c, ...)
{
printf("%c
", c)
}

A. Compile time error
B. Undefined behaviour
C. 97
D. a
Answer: _________
Question 215:

What will be the output of the following C code? #include <stdio.h>
#include <string.h>
int main()
{
char line[3]
fgets(line, 3, stdin)
printf("%d
", strlen(line))
return 0
}

A. 3
B. 1
C. Any length since line did not end with null character
D. Depends on the standard
Answer: _________
Question 216:

What will be the output of the following C code? char str[] =”Good”
scanf(“%s”, str)

A. compile error
B. run-time error
C. good
D. logical error
Answer: _________
Question 217:

What will be the output of the following C code? #include <stdio.h>
int main()
{
FILE *fp = stdout
int n
fprintf(fp, "%d ", 45)
fflush(stdout)
fprintf(stderr, "%d", 65)
return 0
}

A. 45 65
B. 65 45
C. 45
D. Compilation error
Answer: _________
Question 218:

What will be the output of the following C code? #include <stdio.h>
void main()
{
char *p = calloc(100, 1)
p = "welcome"
printf("%s
", p)
}

A. Segmentation fault
B. Garbage
C. Error
D. welcome
Answer: _________
Question 219:

What will be the output of the following C code? #include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%d
", rand() % 1000)
return 0
}

A. Compile time error
B. An integer between 0-1000
C. An integer between 0-999 including 0 and 999
D. An integer between 0-1000 including 1000
Answer: _________
Question 220:

What will be the output of the following C code if following commands are used to run (considering myfile exists)? gcc -otest test.c
./test > myfile
#include <stdio.h>
int main(int argc, char **argv)
{
char c = 'd'
putchar(c)
printf(" %d
", argc)
}

A. d 2 in myfile
B. d 1 in myfile
C. d in myfile and 1 in screen
D. d in myfile and 2 in screen
Answer: _________
Question 221:

What will be the output of the following C code? scanf(“ %d %d %d”,&n1,&n2)

A. read data for two
B. generate error
C. read data for three
D. nothing can be said
Answer: _________
Question 222:

What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10, j = 2
printf("%d
", printf("%d %d ", i, j))
}

A. Compile time error
B. 10 2 4
C. 10 2 2
D. 10 2 5
E. Compile time error
F. 10 2 4
G. 10 2 2
H. 10 2 5
Answer: _________
Question 223:

What will be the output of the following C code? #include <stdio.h>
#include <stdarg.h>
int f(char c, ...)
int main()
{
char c = 97, d = 98
f(c, d)
return 0
}
int f(char c, ...)
{
va_list li
va_start(li, c)
char d = va_arg(li, char)
printf("%c
", d)
va_end(li)
}

A. Compile time error
B. Undefined behaviour
C. a
D. b
Answer: _________
Question 224:

What will be the output of the following C code? #include <stdio.h>
int main()
{
srand(time(NULL))
printf("%d
", rand())
return 0
}

A. Compile time error
B. An integer in the range 0 to RAND_MAX
C. A double in the range 0 to 1
D. A float in the range 0 to 1
Answer: _________
Question 225:

What will be the output of the following C code? #include <stdio.h>
#include <string.h>
int main()
{
char line[3]
FILE *fp
fp = fopen("newfile.txt", "r")
while (fgets(line, 3, fp))
fputs(line, stdout)
return 0
}

A. Compilation error
B. Infinite loop
C. Segmentation fault
D. No.of lines present in file newfile
Answer: _________
Question 226:

What will be the output of the following C code? char str[] = "Hello Nancy“
printf(“
%.7s”, str)

A. Hello Nan
B. Hello
C. Hello N
D. Hello Nancy
Answer: _________
Question 227:

What will be the output of the following C code? #include <stdio.h>
int main(int argc, char **argv)
{
char *s = "myworld"
int i = 3
printf("%10.*s", i, s)
}

A. myw(note:7 spaces before myw)
B. myworld(note:2 spaces before myworld)
C. myworld (note:2 spaces after myworld)
D. myw(note:6 spaces after myworld)
Answer: _________
Question 228:

What is the prototype of scanf function?

A. scanf("controlstring",arg1,arg2,arg3,....,argn)
B. scanf("control string", variable list)
C. scanf(" varible list,", control string)
D. scanf("arg1,arg2,arg3,....,argn", control string)
Answer: _________
Question 229:

What will be the output of the following C code? #include <stdio.h>
#include <math.h>
int main()
{
int i = 90
printf("%f
", sin(i))
return 0
}

A. Compile time error
B. Undefined behaviour
C. 0.893997
D. 1.000000
Answer: _________
Question 230:

What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10, j = 3, k = 3
printf("%d %d ", i, j, k)
}

A. Compile time error
B. 10 3 3
C. 10 3
D. 10 3 somegarbage value
E. Compile time error
F. 10 3 3
G. 10 3
H. 10 3 somegarbage value
Answer: _________
Question 231:

What will be the output of the following C code? #include <stdio.h>
int main()
{
int n
scanf("%d", &n)
ungetc(n, stdin)
scanf("%d", &n)
printf("%d
", n)
return 0
}

A. Compile time error
B. Whatever is typed by the user first time
C. Whatever is typed by the user second time
D. Undefined behaviour
Answer: _________
Question 232:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char buf[12]
stderr = stdin
fscanf(stderr, "%s", buf)
printf("%s
", buf)
}

A. Compilation error
B. Undefined behaviour
C. Whatever user types
D. None of the mentioned
Answer: _________
Question 233:

What form the data must be entered for the given C code? scanf(“%d / %d”, &n1,&n2)

A. 6 xa0 9
B. 6/9
C. compile error
D. run-time error
Answer: _________
Question 234:

What will be the output of the following C code? #include <stdio.h>
int main()
{
short int i
scanf("%hd", &i)
printf("%hd", i)
return 0
}

A. Compilation error
B. Undefined behavior
C. Whatever user types
D. None of the mentioned
Answer: _________
Question 235:

What will be the output of the following C code? #include <stdio.h>
int main()
{
FILE *fp = stdout
int n
fprintf(fp, "%d
", 45)
fprintf(stderr, "%d ", 65)
return 0
}

A. 45 65
B. 65 45
C. 65
D. Compilation error
Answer: _________
Question 236:

Which of the following is the right declaration for fgets() inside the library?

A. int *fgets(char *line, int maxline, FILE *fp)
B. char *fgets(char *line, int maxline, FILE *fp)
C. char *fgets(char *line, FILE *fp)
D. int *fgets(char *line, FILE *fp)
Answer: _________
Question 237:

What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10, j = 3
printf("%d %d %d", i, j)
}

A. Compile time error
B. 10 3
C. 10 3 some garbage value
D. Undefined behaviour
E. Compile time error
F. 10 3
G. 10 3 some garbage value
H. Undefined behaviour
Answer: _________
Question 238:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char *n
scanf("%s", n)
return 0
}

A. Compilation error
B. Undefined behavior
C. Nothing
D. None of the mentioned
Answer: _________
Question 239:

Which of the following fopen() statements are illegal?

A. fp = fopen("abc.txt", "r")
B. fp = fopen("/home/user1/abc.txt", "w")
C. fp = fopen("abc", "w")
D. none of the mentioned
Answer: _________
Question 240:

The syntax of printf() function is printf("control string", variable list)
what is the prototype of the control string?

A. %[flags][.precision][width][length]specifier
B. %[flags][length][width][.precision]specifier
C. %[flags][width][.precision][length]specifier
D. %[flags][.precision][length][width]specifier
Answer: _________
Question 241:

What will be the output of the following C code? #include <stdio.h>
int main()
{
short int i
scanf("%*hd", &i)
printf("%hd", i)
return 0
}

A. Compilation error
B. Somegarbage value
C. Whatever user types
D. Depends on the standard
Answer: _________
Question 242:

What will be the output of the following C code? printf(“
Output: %5d %x %#x”, 234,234,234)

A. Output:234EA0xEA
B. Output:00234 EA 0xEA
C. Output: xa0xa0 234 EA 0xEA
D. ERROR
Answer: _________
Question 243:

What will be the output of the following C code? #include <stdio.h>
#include <stdlib.h>
int main()
{
srand(9000)
printf("%d
", rand())
return 0
}

A. Compile time error
B. An integer in the range 0 to RAND_MAX
C. A double in the range 0 to 1
D. A float in the range 0 to 1
Answer: _________
Question 244:

What will be the output of the following code? char t=’N’
printf(“
%c
%3c
%5c”,t,t,t)

A. N N N
B. N N N
C. N N N
D. N N N
Answer: _________
Question 245:

What will be the output of the following C code? #include <stdio.h>
int main(int argc, char** argv)
{
char *s = "myworld"
int i = 3
printf("%10.*s", i, s)
}

A. myw(note:7 spaces before myw)
B. myworld(note:2 spaces before myworld)
C. myworld (note:2 spaces after myworld)
D. myw(note:6 spaces after myw)
Answer: _________
Question 246:

What is the output of the following C code if there is no error in stream fp? #include <stdio.h>
int main()
{
FILE *fp
fp = fopen("newfile", "w")
printf("%d
", ferror(fp))
return 0
}

A. Compilation error
B. 0
C. 1
D. Any nonzero value
Answer: _________
Question 247:

Which of the following is used during memory deallocation in C?

A. remove(p)
B. delete(p)
C. free(p)
D. terminate(p)
Answer: _________
Question 248:

In the following C program, every time program is run different numbers are generated. #include <stdio.h>
int main()
{
srand(time(NULL))
printf("%d
", rand())
return 0
}

A. True
B. False
C. Depends on the platform
D. Depends on the compiler
Answer: _________
Question 249:

What will be the output of the following C code if 2 characters is typed by the user? #include <stdio.h>
#include <string.h>
int main()
{
char line[3]
fgets(line, 3, stdin)
printf("%d
", line[2])
return 0
}

A. Compilation error
B. Undefined behaviour
C. 0
D. 10(ascii value of newline character)
Answer: _________
Question 250:

What will be the output of the following C code? char str[] =”Too Good”
printf(“
%7s”,str)

A. Too Good
B. Too G
C. Too Go
D. Too
Answer: _________
Question 251:

What will be the output of the following C code? #include <stdio.h>
#include <math.h>
void main()
{
int k = pow(2, 3)
printf("%d
", k)
}

A. 9
B. 8
C. -1
D. 6
Answer: _________
Question 252:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char *s = "myworld"
int i = 9
printf("%*s", i, s)
}

A. myworld
B. myworld(note: spaces to the left of myworld)
C. myworld (note:followed by two spaces after myworld)
D. Undefined
Answer: _________
Question 253:

Which of the following is an invalid method for input?

A. scanf("%d%d%d",&a, &b, &c)
B. scanf("%d %d %d", &a, &b, &c)
C. scanf("Three values are %d %d %d",&a,&b,&c)
D. none of the mentioned
Answer: _________
Question 254:

Which among the following is correct function call for rand() and random()?

A. rand() and random()
B. rand() and random(1)
C. rand(1) and random(1)
D. rand(1) and random()
Answer: _________
Question 255:

What will be the output of the following C code? #include <stdio.h>
#include <stdarg.h>
int f(char c, ...)
int main()
{
char c = 97, d = 98
f(c, d)
return 0
}
int f(char c, ...)
{
va_list li
va_start(li, c)
char d = va_arg(li, int)
printf("%c
", d)
va_end(li)
}

A. Compile time error
B. Undefined behaviour
C. a
D. b
Answer: _________
Question 256:

What will be the output of the following C code? #include <stdio.h>
#include <ctype.h>
int main()
{
char c = 't'
printf("%d
", isspace(c))
}

A. Non-zero number
B. Nothing
C. Error
D. t
Answer: _________
Question 257:

What will be the output of the following C code? #include <stdio.h>
#include <ctype.h>
int main()
{
int i = 9
if (isdigit(i))
printf("digit
")
else
printf("not digit
")
return 0
}

A. digit
B. not digit
C. Depends on the compiler
D. None of the mentioned
Answer: _________
Question 258:

What will be the output of the following C code? #include <stdio.h>
#include <math.h>
int main()
{
unsigned int i = -1
printf("%f
", fabs(i))
return 0
}

A. Compile time error
B. 1
C. -1
D. None of the mentioned
Answer: _________
Question 259:

What will be the output of the following C code if following commands are used to run (considering myfile exists)? gcc -otest test.c
./test < myfile
#include <stdio.h>
int main()
{
char c = 'd'
putchar(c)
}

A. Compile time error (after first command)
B. d in the myfile file
C. d on the screen
D. Undefined behaviour
Answer: _________
Question 260:

What will be the output of the following C code? #include <stdio.h>
#include <ctype.h>
int main()
{
int i = 0
if (isspace(i))
printf("space
")
else
printf("not space
")
return 0
}

A. Compile time error
B. space
C. not space
D. None of the mentioned
Answer: _________
Question 261:

What will be the output of the following C code? #include <stdio.h>
#include <math.h>
void main()
{
int k = sqrt(-4)
printf("%d
", k)
}

A. -2
B. 2
C. Compile time error
D. NaN
Answer: _________
Question 262:

What will be the output of the following C code? #include <stdio.h>
#include <ctype.h>
int main()
{
char i = 9
if (isdigit(i))
printf("digit
")
else
printf("not digit
")
return 0
}

A. digit
B. not digit
C. Depends on the compiler
D. None of the mentioned
Answer: _________
Question 263:

The type va_list in an argument list is used . . . . . . . .

A. To declare a variable that will refer to each argument in turn
B. For cleanup
C. To create a list
D. There is no such type
Answer: _________
Question 264:

Identify X library function for line input and output in the following C code? #include <stdio.h>
int X(char *s, FILE *iop)
{
int c
while (c = *s++)
putc(c, iop)
return ferror(iop) ? EOF : 0
}

A. getc
B. putc
C. fgets
D. fputs
Answer: _________
Question 265:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char n[20]
fgets(n, 19, stdin)
ungetc(n[0], stdin)
scanf("%s", n)
printf("%s
", n)
return 0
}

A. Compile time error
B. Whatever string user types second time
C. Whatever string user types first time
D. First character of whatever user types first time and whatever user types second time
Answer: _________
Question 266:

What will be the output of the following C code? #include <stdio.h>
#include <stdarg.h>
void func(int, ...)
int main()
{
func(2, 3, 5, 7, 11, 13)
return 0
}
void func(int n, ...)
{
int number, i = 0
va_list start
va_start(start, n)
while (i != 3)
{
number = va_arg(start, int)
i++
}
printf("%d", number)
}

A. 3
B. 5
C. 7
D. 11
Answer: _________
Question 267:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char n[] = "hello
world!"
char s[13]
sscanf(n, "%s", s)
printf("%s
", s)
return 0
}

A. hellonworld!
B. hello world!
C. hello
D. hello world!
Answer: _________
Question 268:

What will be the output of the following C code? #include <stdio.h>
#include <ctype.h>
int main()
{
int i = 32
if (isspace(i))
printf("space
")
else
printf("not space
")
return 0
}

A. Compile time error
B. space
C. not space
D. None of the mentioned
Answer: _________
Question 269:

What will be the output of the following C code? #include <stdio.h>
#include <stdarg.h>
int f(int c, ...)
int main()
{
int c = 97
float d = 98
f(c, d)
return 0
}
int f(int c, ...)
{
va_list li
va_start(li, c)
float d = va_arg(li, float)
printf("%f
", d)
va_end(li)
}

A. Compile time error
B. Undefined behaviour
C. 97.000000
D. 98.000000
Answer: _________
Question 270:

What will be the output of the following C code? #include <stdio.h>
int main()
{
char i = '9'
if (isdigit(i))
printf("digit
")
else
printf("not digit
")
return 0
}

A. digit
B. not digit
C. Depends on the compiler
D. None of the mentioned
Answer: _________
Question 271:

What will be the output of the following C code? #include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = stdout
int n
fprintf(fp, "%d", 45)
}

A. Compilation error
B. 45
C. Nothing
D. Depends on the standard
Answer: _________
Question 272:

Which of the following is the correct declaration for ungetc?

A. int ungetc(int c, FILE fp)
B. int ungetc(int *c, FILE fp)
C. int ungetc(int c, FILE *fp)
D. int ungetc(int *c, FILE *fp)
Answer: _________
Question 273:

What will be the output of the following C code? #include <stdio.h>
#include <math.h>
int main()
{
int i = 10
printf("%f
", log10(i))
return 0
}

A. Compile time error
B. 1.000000
C. 2.302585
D. None of the mentioned
Answer: _________
Question 274:

What is meant by 'a' in the following C operation? fp = fopen("Random.txt", "a")

A. Attach
B. Append
C. Apprehend
D. Add
Answer: _________
Question 275:

The syntax of the scanf() is scanf("control string ", arg1,arg2,arg3,....,argn)
the prototype of control string is

A. [=%[width][modifiers]type=]
B. [=%[modifiers][width]type=]
C. [=%[width] [modifiers]]
D. [width][modifiers]
Answer: _________
Question 276:

What will be the output of the following C code considering user typed jkl? #include <stdio.h>
int main()
{
char n[20]
fgets(n, 19, stdin)
ungetc(n[0], stdin)
printf("%s
", n)
return 0
}

A. jkl
B. kl
C. Undefined behaviour
D. jk
Answer: _________
Question 277:

What will be the output of the following C code? #include <stdio.h>
#include <math.h>
void main()
{
int k = fabs(-87)
printf("%d
", k)
}

A. -87
B. 87
C. 78
D. error
Answer: _________
Question 278:

Select the right explanation to the given code. printf(“%*. *f”, 5,4,5700)

A. the minimum field width has to be 4, the precision is given to be 5, and the value to be displayed is 5700
B. the minimum field width is 5, the precision is 4, and the value to be displayed is 5700
C. compile error
D. run-time error
Answer: _________
Question 279:

Which of the following should be used for freeing the memory allocated in the following C code? #include <stdio.h>
struct p
{
struct p *next
int x
}
int main()
{
struct p *p1 = (struct p*)malloc(sizeof(struct p))
p1->x = 1
p1->next = (struct p*)malloc(sizeof(struct p))
return 0
}

A. free(p1) free(p1->next)
B. free(p1->next) free(p1)
C. free(p1)
D. all of the mentioned
Answer: _________
Question 280:

Which of the following function with ellipsis are illegal?

A. void func(...)
B. void func(int, ...)
C. void func(int, int, ...)
D. none of the mentioned
Answer: _________
Question 281:

What will be the output of the following C code? #include <stdio.h>
struct p
{
struct p *next
int x
}
int main()
{
struct p *p1 = calloc(1, sizeof(struct p))
p1->x = 1
p1->next = calloc(1, sizeof(struct p))
printf("%d
", p1->next->x)
return 0
}

A. Compile time error
B. 1
C. Somegarbage value
D. 0
Answer: _________
Question 282:

Which of the following mathematical function requires 2 parameter for successful function call?

A. fmod()
B. div()
C. atan2()
D. all of the mentioned
Answer: _________
Question 283:

How many characters for pushback is guaranteed per file while using ungetc(c, fp)
?

A. Only 1 character
B. Characters within 1 word
C. Characters within 1st new-line
D. All characters upto NULL character
Answer: _________
Question 284:

Which of the following function can be used to terminate the main() function from another function safely?

A. return(expr)
B. exit(expr)
C. abort()
D. both exit(expr) and abort()
Answer: _________
Question 285:

What will be the output of the following C code (when 4 and 5 are entered)? #include <stdio.h>
void main()
{
int m, n
printf("enter a number")
scanf("%d", &n)
scanf("%d", &m)
printf("%d %d
", n, m)
}

A. Error
B. 4 junkvalue
C. Junkvalue 5
D. 4 5
Answer: _________
Question 286:

What will be the output of the following C code? #include <stdio.h>
void main()
{
int n
scanf("%d", n)
printf("%d", n)
}

A. Prints the number that was entered
B. Segmentation fault
C. Nothing
D. Varies
Answer: _________
Question 287:

What will be the output of the following C code? #include <stdio.h>
int main()
{
short int i
scanf("%h*d", &i)
printf("%hd", i)
return 0
}

A. Compilation error
B. Undefined behavior
C. Somegarbage value
D. Depends on the standard.
Answer: _________
Question 288:

The given statement FILE *fptr

A. Defines a pointer to the pre-defined structure type FILE
B. Defines a pointer to the user-defined structure type FILE
C. Defines a pointer to the pre-defined data type FILE DESCRIPTOR
D. Creates a file with the name fptr
Answer: _________
Question 289:

What are the two predefined FILE pointers in C?

A. console and error
B. stdout and stdio
C. stdout and stderr
D. stdio and stderr
Answer: _________
Question 290:

Which one of the following is valid for opening a read-only ASCII file?

A. fileOpen(filename, "r")
B. fopen(filename, "ra")
C. fileOpne(filename, read)
D. fopen(filename, "read")
Answer: _________
Question 291:

What will be the output of the following C code? #include <stdio.h>
struct p
{
struct p *next
int x
}
int main()
{
struct p* p1 = malloc(sizeof(struct p))
p1->x = 1
p1->next = malloc(sizeof(struct p))
printf("%d
", p1->next->x)
return 0
}

A. Compile time error
B. 1
C. Somegarbage value
D. 0
Answer: _________
Question 292:

Which among the following mathematical function do not have a "double" return-type?

A. srand(x)
B. ceil(x)
C. floor(x)
D. both ceil(x) and floor(x)
Answer: _________

Answer Key

1: B
2: C
3: C
4: D
5: A
6: D
7: B
8: B
9: D
10: D
11: B
12: D
13: A
14: B
15: B
16: A
17: C
18: B
19: B
20: C
21: C
22: C
23: C
24: B
25: B
26: C
27: B
28: C
29: B
30: D
31: A
32: A
33: D
34: C
35: A
36: C
37: A
38: B
39: B
40: C
41: A
42: C
43: C
44: B, E
45: B
46: A
47: D
48: D
49: B
50: D
51: C
52: A
53: B
54: A
55: D
56: B
57: D
58: A
59: D
60: B
61: B
62: B
63: D
64: C
65: A
66: B
67: C
68: D
69: C
70: A
71: A
72: B
73: B
74: C
75: A
76: C
77: C
78: C
79: B
80: C
81: D
82: D
83: A
84: A
85: B
86: A
87: B
88: B
89: A
90: D
91: C
92: A
93: A
94: B
95: A
96: B
97: D
98: A
99: B
100: C
101: B
102: D
103: A
104: A
105: A
106: B
107: C
108: B
109: B
110: A
111: A
112: D
113: B
114: A
115: B
116: C
117: B
118: A
119: B
120: D
121: D
122: B
123: B
124: B
125: D
126: A
127: C
128: A
129: A
130: D
131: D
132: A
133: A
134: D
135: B
136: A
137: D
138: A
Solution: The correct answer is A: getc() Let's break down why: getc() is a standard C library function specifically designed to read a single character from a file stream. It takes a file pointer (FILE*) as an argument and returns the character read (as an integer) or EOF if the end of the file is reached or an error occurs. readchar() is not a standard C function for file input. read() is a lower-level function (usually from the POSIX standard) used for reading a block of data from a file descriptor, not a single character. getchar() reads a character from standard input (stdin), which is usually the keyboard, not from a file. So, getc() is the correct function to use when you want to read a single character from a file in C.
139: A
140: B
141: A
142: C
143: C
144: A
145: B
146: A
147: A
148: D
149: A
150: A
151: C
152: D
153: A
154: B
155: D
156: B
157: A
158: D
159: D
160: B
161: A
162: A
163: C
164: A
165: A
166: A
167: A
168: B
169: B
170: D
171: A
172: C
173: B
174: B
175: A
176: B
177: A
178: A
179: B
180: A
181: B
182: C
183: B
184: B
185: D
186: C
187: B
188: B
189: B
190: D
191: C
192: B
193: D
194: A
195: A
196: A
197: B
198: B
199: B
200: A
201: A
202: B
203: C
204: B
205: B
206: A
207: C
208: C
209: A
210: B
211: A
212: B
213: B
214: D
215: B
216: C
217: A
218: D
219: C
220: B
221: B
222: D, H
223: B
224: B
225: C
226: C
227: A
228: A
229: C
230: C, G
231: B
232: C
233: B
234: C
235: A
236: B
237: C, G
238: B
239: D
240: C
241: B
242: C
243: B
244: B
245: A
246: B
247: C
248: A
249: C
250: A
251: B
252: B
253: D
254: A
255: D
256: A
257: B
258: D
259: C
260: C
261: D
262: B
263: A
264: D
265: D
266: C
267: C
268: B
269: B
270: A
271: B
272: C
273: B
274: B
275: A
276: A
277: B
278: B
279: B
280: A
281: D
282: D
283: A
284: B
285: D
286: C
287: A
288: A
Solution: FILE is a pre-defined structure.
289: C
Solution: Besides the file pointers which we explicitly open by calling fopen, there are also three predefined streams. stdin is a constant file pointer corresponding to standard input, and stdout is a constant file pointer corresponding to standard output. Both of these can be used anywhere when a file pointer is called for
for example, getchar() is the same as getc(stdin) and putchar(c) is the same as putc(c, stdout). The third predefined stream is stderr. Like stdout, stderr is typically connected to the screen by default. The difference is that stderr is not redirected when the standard output is redirected.
290: N/A
291: C
292: A