Showing posts from November, 2018

Pointer to Pointer in C Programming [Complete Guide]

As we have learned that we can declare a pointer to any data type. Same as we can also declare a pointer to any pointer.
A pointer is just a reference to any variable (We have discussed). If we declare a pointer just as
int *numberPtr; (Read from right to left numberPtr is a pointer to an int)

This will make a block in memory that can contain the address of an integer variable or we can say numberPtr can point to an integer variable.

If we declare and initialize an integer variable just as
int xyz = 7; and assign the address of that variable to the pointer numberPtr just as
numberPtr = &xyz; then the numberPtr will point to the integer variable xyz as shown in the figure
Now the original topic starts.

We have revised that how we can declare and initialize a pointer with the address of any data type (int, float, char, double etc).
We can also initialize a pointer with the address of another pointer or one pointer can point to one another pointer.

If we are declaring a pointer for a simple varia…

Types of Arrays in C Programming

Arrays are used to store related data items. So arrays are the very important concept to understand.

There are two types of arrays
1. One-dimensional Arrays
2. Multidimensional Arrays

One-Dimensional Arrays:Linear arrays or simple arrays are known as one-dimensional arrays because in this type of arrays data store in one dimension. For example, if we declare an integer array of size 5 such as
int myFirstArray[] = {56,6,10,25,1}; the data will store in one dimension you can see in figure
To read the value from the one-dimensional array we use one subscript. So also known as one subscripted array.

If we want to print 25 from our array we can use statement just like
printf("Value at index 3 : %d", myFirstArray[3]); This will print the value of index 3 just like
Value at index 3 : 25
If I want to change the value of index 4, I will write
myFirstArray[4] = 78; This will change the value at index 4 just as
Read everything about One-dimensional Arrays.
Multidimensional Arrays:In multidimensional a…

Two Dimensional Arrays in C Programming [Complete Guide]

We are already familiar with one-dimensional arrays or simple arrays. In one-dimensional arrays data stores in linear form or we consider it that data is stored in linear form. In one-dimensional arrays, there is only one subscript to access values in an array.

But we can also define two-dimensional arrays having two subscripts so also known as the double-subscripted arrays.

We can declare 2-D arrays just as we declare any simple array.

In one-dimensional arrays when we declare an array like
int arr[3]; This form 3 blocks in memory to store integer numbers.

But when we declare a 2-D array just as
int arr[3][3]; This will form 9 blocks in memory to store integer numbers.

You can relate this with a matrix in calculus with three rows and three columns or 3-by-3 matrix.

The first subscript shows the total number of rows and second subscript shows the total number of columns.

You can understand by understating this image
As you know index in arrays start from 0. So the row numbers are 0,1,2 and column…

Strings in C Programming

Unlike other data items, there is no primitive data type in C Programming which is used to store Strings.

Developers of C Programming believes that String is nothing but an array of characters.

So in C Programming, we store String in the array of characters.

When we declare and initialize an array of character with a String, Just as
char myString[]="BLUE";
An array of the character of size 5 will be formed in memory. As shown in the figure

In an array of characters(used to store the string), the last index of the array will always have '\0' known as NULL. It shows that the String is ending here.

Format specifier for Strings in C Programming is %s. We can use it in print as well as in scan statement. Just as we use %d to get an integer from the user or to print an integer. 
Getting String From User:char name[50];
printf("Enter your name: ");
printf("Your name: %s",name);
Enter your name: Jhon Bravo
Your name: Jhon

As you s…

Data Types in C Programming

In everyday life, we need to store some data. Sometimes we store the data in the written form and sometimes in our own memory.

Let, we have to store data in written form, for this purpose we need a marker and a paper to write. If one has these two things (marker, paper) he/she can store data in written form.

The same concept is in the programming.

In all programming languages, we need to store some data in our program. Sometimes we get the data from the user while the program is running and store in some variable and sometimes we hardcode the data in our program.

Once the data is stored in some variable, we can change it later as needed.

So the conclusion is we can store data in our program.

Now to store the data, we need some variables of the particular data type. For example, if we need to store the whole number, the variable is of different data type and if we want to store floating point value the variable will be of a different data type.

In C programming language, there are many data t…