C Lab programs Archive
Solution: We can allocate memory in 2 ways in C programming. malloc() function is used to allocate memory dynamically. Stdlib.h header file is providing pre-defined functionality to allocate and de-allocate the memory dynamically. In this …
Solution: Pointers are powerful features in C programming. Addressing is important before start of Pointers in C. Address in C If you have a variable called ‘x’ in yprogram then &x will give you its …
Solution: Address operator is used to returns the memory location of specified variable. Pointer operator is used to returns the data which is present in the specified memory location. The following example describes the use …
Solution: We read the input values into variables n1, n2 using pointer variables p1 and p2. We add the values of n1 and n2 through pointers.
Solution: Passing references(addresses) as parameters to function is called “Call By Reference”. We need to specify the pointer type arguments in the called function to collect these references. We can access the information(a, b) of …
Solution: We use calloc() function to allocate memory dynamically to arrays in C programming. We scan the elements into array using “data+i” expression into consecutive memory locations. We consider the first element as largest element …
Solution: Swapping is the concept of interchanging the values of 2 numbers. We use call by reference concept to swap 2 numbers in this code. Read elements into variables a and b in main() function …
Solution: In this program, we define a function add() that returns the address of variable ‘z’. ‘z’ holds the value which is sum of 2 input number x and y. To collect the address returned …
Solution: In this program, we used malloc() function to allocate the memory. After memory allocation, we read the elements into array using for loop with expression “p+i”. Using pointer variable “p” and it’s increment, we …