C Programming 6

COEP
Lets Crack Online Exam

IT Interview Exam Questions: C Programming 6 (IT Interview Exam Question, IT Campus Placement)

Subject: C Programming 6

Part 6: List for questions and answers of C Language

 

Q1. Value of static storage variable

a) changes during different function calls

b) persists between different function calls

c) increases during different function calls

d) decreases during different function calls

 

Q2. Which of the following is not a proper storage class in ‘C’?

a) auto

b) dec

c) static

d) extern

 

Q3. Regarding the scope of the variables identify the incorrect statement:

a) Automatic variables are automatically initialized to 0

b) Static variables are automatically initialized to 0

c) The address of a register variable is not accessible

d) Static variables cannot be initialized with any expression

 

Q4. The function ____ obtains block of memory dynamically

a) calloc

b) malloc

c) Both a and b

d) free

 

Q5. void * malloc(size_t n) returns

a) Pointer to n bytes of uninitialized storage

b) NULL if the request cannot be satisfied

c) Nothing

d) Both a and b are true

 

Q6. calloc() returns a storage that is initialized to

a) Zero

b) Null

c) Nothing

d) One 

 

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

a) int

b) Pointer returned by malloc()

c) Pointer returned by calloc()

d) Both b and c

 

Q8. What is the output of this C code

#include <stdio.h>

    void main()

    {

        char *p = calloc(100, 1);

        p = “welcome”;

        printf(“%s\n”, p);

    }

a) Segmentation fault

b) Garbage

c) Error

d) welcome

 

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

a) Static area

b) Stack area

c) Heap area

d) Both b and c

 

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

 

Q11. Which one is used during memory deallocation in C?

a) remove(p);

b) delete(p);

c) free(p);

d) terminate(p);

 

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

 

Q13. 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 location it was initialized with

 

Q14. calloc initialises memory with all bits set to zero

a) true

b) false

c) Depends on the compiler

d) Depends on the standard

 

Q15. realloc(ptr, size), where size is zero means

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

 

Q16. With every use of memory allocation function, what function should be used to release allocated memory which is no longer needed?

a) dropmem()

b) dealloc()

c) release()

d) free()

 

Q17. Physically placing the machine instructions and data into main memory is done by

a) Linker

b) Loader

c) Code Generator

d) Interpreter

 

Q18. Which header file should be included to use function like malloc() and calloc()?

a) memory.h

b) stdlib.h

c) string.h

d) dos.h 

 

Q19. Which data structure is used by malloc() for object creation?

a) Heap

b) Tree

c) Stack

d) Queue

 

Q20. Which of the following statement is correct prototype of the malloc() function in c ?

a) int* malloc(int);

b) char* malloc(char);

c) unsigned int* malloc(unsigned int);

d) void* malloc(size_t); 

 

Part 6: List for questions and answers of C Language

 

Q1. Answer: b

 

Q2. Answer: b

 

Q3. Answer: a

 

Q4. Answer: c

 

Q5. Answer: d

 

Q6. Answer: a

 

Q7. Answer: d

 

Q8. Answer: d

 

Q9. Answer: c

 

Q10. Answer: b

 

Q11. Answer: c

 

Q12. Answer: d

 

Q13. Answer: c

 

Q14. Answer: a

 

Q15. Answer: b

 

Q16. Answer: d

 

Q17. Answer: b

 

Q18. Answer: b

 

Q19. Answer: a

 

Q20. Answer: d