Skip to main content

Posts

Showing posts from April, 2016

C Interview Questions And Answers - Part 1.

What is the difference between pass by value and pass by reference? Answer: We can pass the parameters in a function in two different ways in C programming. Pass by value: In this approach we pass the copy of actual variables in function as a parameter. Hence any modification on parameters inside the function will not reflect in the actual variable. For example: #include<stdio.h> int main() {     int a=5,b=10;     swap(a,b);     printf("%d %d",a,b);     return 0; }   void swap(int a,int b) {     int temp;     temp =a;     a=b;     b=temp; } Output: 5  10 Pass by reference: In this approach we pass the memory address of actual variables in function as a parameter. Hence any modification on parameters inside the function will reflect in the actual variable. For example: #incude<stdio.h> int main() {     int a=5,b=10;     swap(&a,&b);     printf("%d %d",a,b);     return 0; } void swap(in