Author: learnconline

2-Dimensional (2D) Array in C Programming Language 14

2-Dimensional (2D) Array in C Programming Language

An array is a collective name given to a group of similar variables. An array can be 1-Dimensional, 2-Dimensional, 3-Dimensional and so on. In this topic, we will discuss 2-Dimensional (2D) arrays in C Programming Language. Let us understand what two dimensional arrays are. Consider the following matrix. 11 12 13 A= 14 15 16 17 18 19 The above-mentioned matrix is 3 by 3. The matrix elements can be accessed using the formula A[m,n], where m represents row number and n represents column number. Thus, the first element i.e. 11 is represented as A[0,0]. Similarly, A[0,1] = 12 A[0,2]...

C Arrays – 1D (1 Dimensional) 29

C Arrays – 1D (1 Dimensional)

An array in C is a collective name given to a group of similar variables. C arrays can be 1-Dimensional, 2-Dimensional, 3-Dimensional and so on. In this topic, we will discuss 1-Dimensional (1D) arrays in C. So lets start with 1D array in C. Let us understand C arrays with the help of an example. void main(){ int arr[3],i; printf(“Enter 3 values\n”); for(i=0;i<3;i++) { scanf(“%d”,&arr[i]) } printf(“The entered values are:\n”); for(i=0;i<10;i++) { printf(“%d\t”,arr[i]) } } Explanation: int arr[3] statement declares an array capable of holding 3 integer values. The first value can be accessed using arr[0]. Similarly second value can...

Function Prototype in C Language 7

Function Prototype in C Language

As we all know, before using a variable we need to declare it. Similarly, before using a function we need to declare the function. This declaration of the function is called as function prototyping. Consider the below program. float fnGetAverage(int, int); void main() { int x,y; float z; printf(“\nEnter the values for x and y”); scanf(“%d %d”, &x, &y); z = fnGetAverage(x, y); //function call printf(“\nThe average is %d”, z); } float fnGetAverage(int a, int b) { //function definition float c; c = (a+b)/2; //calculating average return c; //returning the value } There is one statement before the main() function....

Pointers in C 38

Pointers in C

Pointers in C is one of the excellent feature introduced in C. It makes the programming very interesting. A pointer in C is a variable that represents the location (rather than the value) of a data item. Talking like a layman, C pointers points to an object or something. Let us understand C pointers in detail. Before learning the basics of pointers, let us understand how the variable is stored in the memory. When we declare a variable and assign a value to the variable, we are actually naming the memory location at which the value will be stored. The...

Function declaration and Prototype in C Programming Language 19

Function declaration and Prototype in C Programming Language

By default, any C function returns an int value. If we want that the function should return a value other than int then we need to explicitly mention it in the function definition. Let us understand this using an example. Example 1: float fnGetAverage(int, int); //function prototype void main() { int x,y; float z; printf(“\nEnter the values for x and y\n”); scanf(“%d %d”, &x, &y); z = fnGetAverage(x,y); //function call printf(“\nThe average is %f”, z); } float fnGetAverage(int a, int b) { //function definition float c; c = (a+b)/2; //calculating average return c; //returning the value } Output: Enter the...

Functions in C 27

Functions in C

Let us understand the concept of functions in C language with the help of day to day scenario. Let us suppose that we want to write a program that will perform all the operations required for banking. So we will have to write a program that will have following steps: Accept account number and other personal details of the customer as a input Accept the details of the transactions to be performed If the customer wants to withdraw the money, then program should fetch the balance amount and perform eligibility check After performing eligibility check, the money is deducted from...

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