What is purpose of return type in main function in C?

What is purpose of “return 0” in main () function in C and why not to prefer using void like “void main()”? main function declaration example, int main(){ printf(“Hello”); return 0; }   Question: What is purpose of return type in main() function in C? For example, we have written “int main ()”, means, it returns … Read more What is purpose of return type in main function in C?

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. “if (printf(“Hello World”)) ;”   Elaborating, Intent of the question is that we can print values on console screen using printf function as shown in below program. int main(){ printf(“hello world”); return 0; } Output: hello world But, … Read more How to print hello world without semi colon in C?

malloc function in C programing with 3 example scenarios

malloc function in c programing 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 … Read more malloc function in C programing with 3 example scenarios

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 … Read more Explain malloc calloc realloc free in c with example

do while Vs while loop in C Programing?

Answer: Difference between do while and while loop: 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 below example, “interviewsansar.com” will be printed once using do…while loop whereas … Read more do while Vs while loop in C Programing?

include guards – why to write in header files – C, C++

Answer: include guards in header file in C, C++ is used to avoid compiler error i.e. redefinition of function, variable or class. #include guards also know as header guards technique are heavily used in C and C++ projects that have multiple headers and source files. In fact, include guards prevent inclusion of a header file … Read more include guards – why to write in header files – C, C++

Explain pass by value and pass by reference in C programing

Answer: Detailed explanation of pass by value and pass by reference in C programing 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 … Read more Explain pass by value and pass by reference in C programing

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 … Read more memcpy vs strcpy including performance C++

Explain command line arguments in C, C++ with real scenario

Command line arguments in C, C++ programs supply values from outside of a program. The same concept of command line argument is applied to all the languages  for example, c, c++,c# and java etc. Also, command line arguments are applicable to scripts also. Some time we get a requirement in a real time application to … Read more Explain command line arguments in C, C++ with real scenario