important questions in c programming for college
Answers
Answer:
important questions in c programming.
Explanation:
1) What is the difference between declaration and definition of a variable/function?
Ans: Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them. But the declaration of a variable/function serves an important role. And that is the type of the variable/function. Therefore, when a variable is declared, the program knows the data type of that variable.
2) What are the different storage class specifiers in C?
Ans: auto, register, static, extern.
3) What is the scope of a variable? How are variables scoped in C?
Ans: The scope of a variable is the part of the program where the variable may directly be accessible. In C, all identifiers are lexically (or statically) scoped
4) When should we use pointers in a C program?
Ans: To get the address of a variable
2. For achieving pass by reference in C: Pointers allow different functions to share and modify their local variables.
3. To pass large structures so that a complete copy of the structure can be avoided.
4. To implement “linked” data structures like linked lists and binary trees.
5) What is a NULL pointer?
Ans: NULL is used to indicate that the pointer doesn’t point to a valid location. Ideally, we should initialize pointers as NULL if we don’t know their value at the time of declaration
6) What is a Dangling pointer?
Ans: Dangling Pointer is a pointer that doesn’t point to a valid memory location. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.
7) What is a memory leak? Why it should be avoided?
Ans: Memory leak occurs when programmers create a memory in heap and forget to delete it. Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.
8) What are the local static variables? What is their use?
Ans: A local static variable is a variable whose life doesn’t end with a function call where it is declared. It extends for the lifetime of the complete program. All calls to the function share the same copy of local static variables. Static variables can be used to count the number of times a function is called. Also, static variables get the default value is 0. For example, the following program prints “0 1”