Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PPS - Unit 5 Objective Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

UNIT 5 – Objective Questions with Answers

1. Which of the following true about FILE *fp

A. FILE is a keyword in C for representing files and fp is a variable of FILE type.


B. FILE is a stream
C. FILE is a buffered stream
D. FILE is a structure and fp is a pointer to the structure of FILE type

2. Which of the following mode argument is used to truncate?

A. a
B. w
C. f
D. t

3. The first and second arguments of fopen() are

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

4. FILE is of type ______

A. int type
B. char * type
C. struct type
D. None of the mentioned

5. fseek() should be preferred over rewind() mainly because

A. rewind() doesn't work for empty files


B. rewind() may fail for large files
C. In rewind, there is no way to check if the operations completed successfully
D. All of the above

6. FILE reserved word is?

A. A structure tag declared in stdio.h


B. One of the basic datatypes in c
C. Pointer to the structure defined in stdio.h
D. It is a type name defined in stdio.h

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

A. "b"
B. "B"
C. "binary"
D. "01"

8.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.

9. Which type of files can‟t be opened using fopen()?

A. .txt
B. .bin
C. .c
D. None of the above

10. 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 above

11.If there is any error while opening a file, fopen will return?

A. Nothing
B. EOF
C. NULL
D. Depends on compiler
12.It is not possible to combine two or more file opening mode in open () method.

A. True
B. False

13.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

14.Which is true?

A. The symbolic constant EOF is defined in


B. The value is -1
C. The symbolic constant EOF is defined in & value is -1
D. Only value is -1

15. Prior to using a pointer variable it should be

A.Declared

B. Initialized

C. Both declared and initialized

D.None of these

16. Consider the declaration:


char x[]="WHATIZIT";
char *y="WHATIZIT";
The output of puts(x) an puts(y) will be

A.Will be the same

B. Different

C. Not related

D.Error

17. In C a pointer variable to an integer can be created by the declaration


A. int p*;

B. int *p;

C. int +p;

D. int $p;

18. getc() returns EOF when

A. When getc() fail to read the character


B. When end of file is reached
C. Both A and B
D. None of the above

19. 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)

20. 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

21. 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

22. Local variables are stored in an area called ___________


a) Heap
b) Permanent storage area
c) Free memory
d) Stack
23. The size of both stack and heap remains the same during run time.
a) True
b) False

24. Choose the statement which is incorrect with respect to dynamic memory allocation.
a) Memory is allocated in a less structured area of memory, known as heap
b) Used for unpredictable memory requirements
c) Execution of the program is faster than that of static memory allocation
d) Allocated memory can be changed during the run time of the program based on the
requirement of the program

25. Which of the following header files must necessarily be included to use dynamic memory
allocation functions?
a) stdlib.h
b) stdio.h
c) memory.h
d) dos.h

26. The type of linked list in which the node does not contain any pointer or reference to the
previous node is _____________
a) Circularly singly linked list
b) Singly linked list
c) Circular doubly linked list
d) Doubly linked list

27. Which of the following is an example of static memory allocation?


a) Linked list
b) Stack
c) Queue
d) Array

28. The advantage of using linked lists over arrays is that ________
a) Linked list is an example of linear data structure
b) Insertion and deletion of an element can be done at any position in a linked list
c) Linked list can be used to store a collection of homogenous and heterogeneous data
types
d) The size of a linked list is fixed

29. What will be the output of the following C code?


#include<stdio.h>
#define max 100
main()
{
#ifdef max
printf("hello");
}

a)100
b)hello
c)“hello”
d) error

30. _______________ is the preprocessor directive which is used to end the scope of #ifdef.
a) #elif
b) #ifndef
c) #endif
d) #if

31. What will be the output of the following C code?

#include<stdio.h>
void main()
{
#ifndef max
printf("hello");
#endif
printf("hi");
}
a)hello
b)hellohi
c)error
d) hi

32. What will be the output of the following C code?


#include<stdio.h>
#define san 557
main()
{
#ifndef san
printf("yes");
#endif
printf("no");
}
a)error
b)yes
c)no
d) yesno

33. The preprocessor directive which checks whether a constant expression results in a zero or
non-zero value __________
a)#if
b)#ifdef
c)#undef
d) #ifndef

34. What will be the output of the following C code?

#include<stdio.h>
#define max 100
void main()
{
#if(max%10)
printf("KEC");
#endif
printf("GHAZIABAD");
}
a)error
b)KEC
c)GHAZIABAD
d) KECGHAZIABAD

35. The preprocessor directive which is used to remove the definition of an identifier which
was previously defined with #define?
a)#ifdef
b)#undef
c)#ifndef
d) #def
36. What will be the output of the following C code?

#include<stdio.h>
#define hello 10
void main()
{
printf("%d",hello);
#undef hello
printf("%d",hello);
}
a)10
b)hello
c)error
d) 1010

37. What will be the output of the following C code?

#include <stdio.h>
#define a 2
main()
{
int r;
#define a 5
r=a*2;
printf("%d",r);
}
a)10
b)4
c)2
d) 5

38. Which among the following is the odd one out?


a) printf
b) fprintf
c) putchar
d) scanf
39. For a typical program, the input is taken using _________
40. What is the value of EOF?
a) -1
b) 0
c) 1
d) 10

41. Which of the following header declares mathematical functions and macros?
a) math.h
b) assert.h
c) stdmat. h
d) stdio. H

42. What will be the output of the following C code?

#include <stdio.h>
int main()
{
int i = 10;
void *p = &i;
printf("%d\n", (int)*p);
return 0;
}
a)Compile time error
b) Segmentation fault/runtime crash
c)10
d) Undefined behaviour

43. What is the output of following program?


# include <stdio.h>
voidfun(intx)
{
x = 30;
}

intmain()
{
inty = 20;
fun(y);
printf("%d", y);
return0;
}
44. Output of following program?
# include <stdio.h>
voidfun(int*ptr)
{
*ptr = 30;
}

intmain()
{
inty = 20;
fun(&y);
printf("%d", y);

return0;
}

45. What is (void*)0?

aRepresentation of NULL pointer


bRepresentation of void pointer
C.Error
dNone of above

46. Are the expression *ptr++ and ++*ptr are same? _________

47. What is the output of this C code?

int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf(" p ");
else
printf("nullp");
if (q)
printf("q\n");
else
printf(" nullq\n");
}

48. What is the output of this C code?

int main()
{
int i = 10;
void *p = &i;
printf("%d\n", (int)*p);
return 0;
}

49. What is the output of this C code?

int main()
{
int i = 10;
void *p = &i;
printf("%f\n", *(float*)p);
return 0;
}

50. What is the output of this C code?

int *f();
int main()
{
int *p = f();
printf("%d\n", *p);
}
int *f()
{
int j = 10;
return &j;
}

1.D 2.B 3.A 4.C 5.C 6.D 7.A 8.C 9.D 10.D
11.C 12.B 13.D 14.C 15.c 16.a 17.b 18.C 19.A 20.B
21.C 22.D 23.B 24.C 25.A 26.B 27.D 28.B 29.D 30.C
31.B 32.C 33.A 34.D 35.B 36.C 37.A 38.D 39.scanf 40.a
41.a 42.a 43.20 44.30 45.a 46.not 47. 48. 49.00 50.10
same nullp complier
nullq error

You might also like