Category: Learn C Online

Understanding the difference between pass by value and pass by reference in C 0

Understanding the difference between pass by value and pass by reference in C

Let us understand the difference between pass by value and pass by reference in C. Given below is a simple C program that illustrates the difference between ordinary arguments, which are passed by value, and pointer arguments, which are passed by reference. #include<stdio.h> void funct1(int a, int b); /*function prototype*/ void funct2(int *pa, int *pb); /*function prototype*/ void main() { int a = 1; int b = 3; printf(“\nBefore calling funct1: a=%d b=%d”, a, b); funct1(a, b); printf(“\nAfter calling funct1: a=%d b=%d”, a, b); printf(“\nBefore calling funct2: a=%d b=%d”, a, b); funct2(&a, &b); printf(“\nAfter calling funct2: a=%d b=%d”, a, b);...

Unions in C Programming Language 2

Unions in C Programming Language

Unions in C programming language (like structures) contains members whose individual data type may differ from one another. However, the members within a union all share the same storage area within the computer’s memory whereas each member within a structure is assigned its own unique storage area. Thus, unions in C are used to conserve memory. They are useful for applications involving multiple members, where values need not be assigned to all the members at any one time. Within a union in C, the bookkeeping required to store members whose data types are different (having different memory requirements) is handled...

Program in C that reads radius of a circle and calculates its area 1

Program in C that reads radius of a circle and calculates its area

The below program in C will accepts the radius of a circle from the user and calculates its area and displays the calculated result to the user on the screen. Explanation Step 1: Read the radius Step 2: Calculate the area by applying the formula: Area = (pi)*r2 = 3.14 * r2 #include<stdio.h> #include<conio.h> void main() { float radius, area; printf(“Radius = ?”); scanf(“%f”, &radius); //calculate the area area = 3.14 * radius * radius; //display the calculated result printf(“Area = %f”, area); getch(); } Output: Radius = ?5 Area = 78.500000

Multi-Dimensional Arrays in C Programming Language 3

Multi-Dimensional Arrays in C Programming Language

Let’s understand the concept of multi-dimensional arrays in C programming language. Although arrays with more than two dimensions are not commonly used, C does allow any number of dimensions to be declared. This is done by listing maximum size of all dimensions of the array. For example, the declaration: int a[4][10][6]; declares a three-dimensional array. The first element in the array is designated as a[0][0][0] and the last element as a[3][9][5]. Thus, generally speaking, multidimensional arrays in C programming language are defined in much the same manner as one-dimensional arrays, except that a separate pair of square brackets are required...

Compare Automatic, Register, Static and External Variables in C 2

Compare Automatic, Register, Static and External Variables in C

Let us understand the difference between various storage classes in C programming language. Below is the table that will show difference between Automatic, Register, Static and External Variables storage Classes in C. Feature Automatic Variable Register Variable Static Variable External Variable 1 Keyword Used auto register static extern 2 Storage Memory CPU registers Memory Memory 3 Default initial value Garbage Value Garbage Value Zero Value Zero Value 4 Scope Local to the block in which the variable is defined Local to the block in which the variable is defined Local to the block in which the variable is defined Global...

Operations on Pointers in C Programming Language 3

Operations on Pointers in C Programming Language

In C Programming Language, the only operations that can be carried out on pointers are summarized below: A pointer variable can be assigned the address of an ordinary variable (e.g., pv = &v) A pointer variable can be assigned the value of another pointer variable (e.g., pv = px) provided both the pointers point to objects of the same data-type A pointer variable can be assigned a null (zero) value (e.g., pv =NULL, where NULL is a symbolic constant that represents the value 0) An integer quantity can be added to or subtracted from a pointer variable (e.g., pv +...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet