Skip to main content

Basic Concept of Pointer in C and it's uses #DOTC_Mdb

Pointers in C.

 

Hello Everyone,

Today we will discuss about Pointer in C program. In Simple word Pointer in C is special type of variables which holds memory address of any variable. Before going to know more about Pointer . Please see my below blog where in archive folder where you will able to find all the previous topics.

dheeraj60.blogspot.com

Let’s Start with Pointer in C . Pointer is basically used to see the address of variable which we assigned in the program. In other word we can say A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address. Suppose we declare any variable of int type like int i=20; and I want to see the address of that value then through pointer we can easily see the address of variable i which stored in the memory location with different format.

Syntax of Declaring Pointer is :

Int *p;  -- for integer data type

double *p; - for double data type

float *p ; - For float data type

char * Ch – for character data type

Note : Actual data type of the value of all pointers, whether it is integer, float, double or character is saved in  a long hexadecimal number that represents a memory address of variables.

 

Let’s understand with one simple Program where we use integer data type and assigned that value and get the address by using Pointer.

 

Program is as below:

#include <stdio.h>

#include <stdlib.h>

int main()

{

 int a = 100;

   int *p;

   p=&a;

   printf("value of a is : %d\n", a);

   printf("Address of variable a is %p", *p);

   return 0;

   }

Here  in above program we declare pointer int *p; and already assigned the value of variable a=100  and address of variable assigned in p and through print f command we display the variable value with  its address also by using pointer by using %p in printf as we use %d for int data type.

Below is the output of above code in Compiler Code Block with both variable values with its address location.

 Here we see both the variable value with address in program by using Pointer.

 

Let’s write one more Program where we can see the  values of  variables  with address by using pointer with same concept.

 

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

 int  a = 100;  

   int  *p;       

 

   p = &a; 

 

   printf("Address of var variable: %x\n", &a  );

 

      printf("Address stored in p variable: %x\n", p );

      printf("Value of *p variable: %d\n", *p );

 

 

   }

 

Here actual variable declaration of a is 100 then we declare pointer *p  then we store the address of a in pointer variable by using  p = &a . in second print f statement we print address stored in pointer variable and in last print f we access the value using the pointer.

 

Below is the output of above Program in compiler  code  Block .

 


Here you can easily trace the address of variable and can access the actual value using the pointer. Hope you are able to understand the basics of Pointer.

 

Let’s understand one more program by using Array in pointer to see the output of value with address.

 

Program is Below

 

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

 int  marks[] = {70,80,90};

   int  *p[3],i;

 

for (i=0; i<3; i++)

{

    printf("%d\n",marks[i]);

    p[i]=&marks[i];

}

 

for (i=0; i<3; i++)

{

  printf("%d",*p[i]);

}

return 0;

   }

 

Here through array we can display the values of marks and through pointer we also show the address of variable.

Please see the output of above program in compiler code block for your understanding.

 

 

See the output as we can see the marks and address of variable which we used to see by pointer using array.

Hope you are able to understand the basic concept of Pointer and can write programs to get the address of any variables etc by using simple as well as array program so please practice as much as you can.Pointer is a big topic which includes Pointers to pointers and pointers used in functions etc which I am going to cover in next blog.

 

Please read this blog carefully so that it’s easy for you to understand more topics in Pointers with Programs and it’s uses and benefits.

Thanks


Comments

Post a Comment

Popular posts from this blog

SQL and Classification of SQL in Oracle Database #Diksha Oracle Training Centre

  SQL and Classification of SQL in Oracle Database.   SQL is Structured Query Language , which is used for storing, manipulating and retrieving data stored in a relational database .SQL is the standard language for RDBMS. All the Relational Database Management Systems (RDMS) like Oracle, MySQL, Sybase, Informix, IBM DB2 and Microsoft SQL Server use SQL as their standard database language. Oracle is one of the more secured database as compared to other databases. Importance of   SQL : SQL and PL/SQL is a backend process where all data is stored and retrieved in GUI which created either by any programming languages like Java, C++, PHP etc. so we need to have very secure database so that there will be no impact for users. SQL allows users to access data in the relational database management systems. SQL is used to communicate with a database.SQL and PL/SQL allows users to create and drop databases tables , views , stored procedures , functions , packages , trigger etc. SQL allows

Materialized View uses and Benefits in Database #DOTC_Mdb

Materialized View uses and Benefits in Database. Hello Everyone, Today we will discuss about Materialized view as it’s play important role in database. We already discussed about Simple Views and complex views in my previous blog. Before Materialized view go through my previous blog which related to simple view. https://dheeraj60.blogspot.com/2020/05/benefits-of-creating-and-using-view-in.html As we know View is not a database object and not like table which is stored in database, but view can be created from base table a view is an SQL statement that’s stored in the database. This statement, or view, has a name.A view looks and acts a lot like a table. It has columns and rows, and can be included in SELECT queries just like a table. In other word we can say View is a virtual/logical table which is basically used for security purpose. Let’s understand   about   Materialized view : A materialized view is a view that stores the results of the view’s query. Whenever you query the ma

Top 50 Interview Questions On SQL and PL/SQL #DOTC_Mdb

                    Top 50 Interview Questions On SQL and PL/SQL. Today we will Discuss Top 50 interview questions and answers of SQL and PL/SQL which is frequently asked in interview.     Question 1: What is SQL and Classification of SQL? Answer SQL is a Structure Query Language which is vastly used in RDBMS database like Oracle, Sybase, DB2 , Microsoft SQL server etc.   Classification of SQL is as below: DDL (Data Definition Language):  Commands are  create , alter , drop , truncate etc DML (Data Manipulation Language) : Commands are  insert,update and delete . TCL (Transaction Control Language ) : Commands are  Commit , Rollback and Save point. DCL (Data Control Language) : Commands are Grant , Revoke Question 2:    What is meant by Joins? What are the types of join? Answer Joins are basically used to extract/get data from multiple tables using some common columns or conditions and also by using alias to fulfill the condition.   There are various types of Joins as li