What is the purpose of “return 0” in main () function in C and why not to prefer using void like “void main()”? Here’s the main function declaration example with return 0, Question: What is purpose of return type in main() function in C? For example, we have written “int main ()”, means, it returns […]
How to print hello world without semi colon in C?
We can print hello world without using semi colon using if condition in C program as below. Elaborating, Intent of the question is that we can print values on console screen using printf function as shown in below program. Output: hello world But, how you can print hello world without semi colon? Meaning, we don’t […]
Null Pointer | Void Pointer | Dangling pointer – C | C++ Notes
Notes on NULL pointer, void pointer and dangling pointer in C and C++ with examples, uses and answer to questions e.g. why to use null pointer, what is void pointer, what is dangling pointer and how to avoid it and why we should avoid it , difference between NULL pointer and void pointer etc. NULL […]
Notes on Function Pointer in C – Uses Callback Example
Complete notes on function pointer in C or say pointer to function in C programming – Example of declaration, typedef, real time uses as callback function with program examples. Real life use of call back function is extracted from one of the real product scenario as a pseudo code. Function pointer in C Function pointer […]
Interview questions on malloc function in C with 3 example scenarios
malloc function in c programming examples interview question based on scenarios – Write programs for following scenarios: Q-1: Allocate memory dynamically using malloc() function for 1 integer, store value 10 and read it.Q-2: Create memory block for 10 integers and store and read numbers from 0-9.Q-3: Copy String from an array char[] =”Hello World” to […]
Explain malloc calloc realloc free in c with example
Answer includes malloc calloc realloc free in c with example Answer: Dynamic memory allocation in C language programming is the process of memory allocation from heap memory at run time. In other word, when memory is allocated from heap during program execution is called dynamic memory allocation. Also note that, in dynamic memory allocation, memory […]
do while Vs while loop in C Programing?
Answer: Difference between do while and while loop in C programming: do…while loop guaranteed to execute at least one time whereas while loop does not. All statements within do…while loop get executed first and then while condition is checked. Hence, it executes at least one time. In the below example, the string “interviewsansar.com” will be […]
Include guards – why to write in header files – C, C++
Answer: The include guards in header file in C, C++ is used to avoid compiler error i.e. redefinition of function, variable or class. The #include guards (also know as header guards) technique are heavily used in the C and C++ projects that have multiple headers and source files. In fact, the include guards prevent inclusion […]
Explain pass by value and pass by reference in C programming
Answer: Detailed explanation of pass by value and pass by reference in C programming with example. Parameters to a function can be passed in two ways i.e. pass by value and pass by reference in C language programming. Actually, pass by reference is nothing but the address of variable that we pass to a function […]
memcpy vs strcpy including performance C++
memcpy() function: memcpy function copies specified number of bytes from source buffer to destination buffer. Actually, programmer supply the size of data to be copied. memcpy() does not check for any terminating null character in source buffer. Actually, it doesn’t care what content is there in the memory. Just it copy the specified number of […]