Skip to main content

POINTERS EXAMPLE IN C PROGRAMMING

Simple example to understand how pointer works

Syntax:

Datatype *pointer_name;

Example:

  1. #include <stdio.h> 
  2. int main ()
  3. {
  4.    int  var = 20;   // actual variable declaration 
  5.    int  *ip;        // pointer variable declaration 
  6.    ip = &var;  // store address of var in pointer variable
  7.    printf("Address of var variable: %x\n", &var  );
  8.  
  9.    /* address stored in pointer variable */
  10.    printf("Address stored in ip variable: %x\n", ip );
  11.  
  12.    /* access the value using the pointer */
  13.    printf("Value of *ip variable: %d\n", *ip );
  14.    return 0;
  15. }

Output:

Address of var variable: bffd8b3c
Address stored in ip variable: bffd8b3c
Value of *ip variable: 20

Description:

This topic seems little bit difficult but its very simple. Key point to remember in pointers
  • Declaring a pointer:                                             datatype *pointer_name;
  • Initialize a pointer :                                              pointer_name = &variable_name
  • Get the address of pointer:                                 use pointer_name(ex: line 10)
  • Get value stored in address of pointer:              *pointer_name(ex:line 13)

Line 4:Declares and initializes variable.

Line 5: This is how we declare a pointer.Now what pointer does is , it actually stores address of variable.

Line 6: This is how we store address of variable. '&' sign is used to get address of the variable.

Line 10: Shows how to print address of variable (or pointer value) on console.Here "%x" displays the hexadecimal value of the address.

Line 13:This line shows how to display the value stored in the address present in the pointer.
Suppose pointer carries address as 1001(for example). Then the value in 1001 will be displayed by line 13. NOTE: Not necessary address can be 1001 only.

рдорд░ाрдаीрдд рд╡рд░्рдгрди :

рдУрд│ рек: рд╡рд░िрдПрдм्рд▓рдЪी рдЬाрдЧा рдоेрдорд░ी рдордз्рдпे рдмрдирддे рд╡ рдд्рдпा рд╡рд░िрдПрдм्рд▓рдордз्рдпे рдХिंрдордд рдаेрд╡рд▓ी рдЬाрддे . 

рдУрд│ рел:рдкोрдЗंрддрд░ рд╣ा рд╕ुрдж्рдзा рдПрдХ рд╡рд░िрдПрдм्рд▓ рдЖрд╣े  рдЬो рдоेрдоोрд░ी рдЪा рдкрдд्рддा рдаेрд╡рдг्рдп рдХрд░िрддा рд╡ाрдкाрд░рд▓ा рдЬाрддो . 

рдУрд│ рем:рд╣्рдпा рдУрд│ рдордз्рдпे рджिрд▓ेрд▓्рдпा рдкрдж्рдзрддीрдиे рд╡рд░िрдПрдм्рд▓рдЪा рдкрдд्рддा рдкोрдЗंрддрд░ рдордз्рдпे рдаेрд╡рд▓ा рдЬाрддो. рдд्рдпा рд╕ाрдаी рд╣ा '&' рдЪिрди्рд╣ рд╡ाрдкрд░рд▓ा рдЬाрддो,

рдУрд│ резреж: рд╣्рдпा рдУрд│ рдордз्рдпे рдЖрдкрдг рдмрдШू рд╢рдХрддो рдХि рдХрд╢्рдпा рдк्рд░рдХाрд░े рдЖрдкрдг рдкोрдЗंрддрд░ рдордзрд▓ा рдкрдд्рддा рдХрди्рд╕ोрд▓рд╡рд░ рд▓िрд╣ूрди рдмрдШू рд╢рдХ्рддो. 

рдУрд│ резрей:рд╣्рдпा рдУрд│ рдордз्рдпे рдкोрдЗрди्рддेрд░ рдордз्рдпे рджेрд▓ेрд▓्рдпा рдкрдд्рддेрдд рдХाрдп рдХिंрдордд рдЖрд╣े рддे рдХाрдбू рд╢рдХ्рддो. рдУ рдХрди्рд╕ोрд▓ рд╡рд░ рд▓िрд╣ू рд╢рдХ्рддो.  
 









Comments

Popular posts from this blog

IOT : GARDEN WATER SPRINKLER SYSTEM

IoT projects have gained immense popularity due to their ability to leverage the power of interconnected devices and data to create innovative solutions across various domains. IoT projects involve integrating sensors, actuators, and communication technologies to enable the seamless exchange of data between physical devices and the internet. These projects range from simple DIY experiments to complex industrial applications, each offering unique opportunities to transform our lives and improve efficiency. Whether it's creating a smart home automation system, monitoring environmental conditions, optimizing energy usage, or developing intelligent transportation systems, applications of IoT open up a world of possibilities for innovation and connectivity. By harnessing the potential of IoT, we can build intelligent and interconnected systems that revolutionize industries, enhance daily life, and pave the way for a more efficient and sustainable future. In this project we will be using...

POWER BI - THE ARCHITECTURE

Power BI Architecture: A Comprehensive Guide to Building Effective Data Analytics Solutions     Understanding Power BI Architecture: Power BI's architecture comprises four main components, each playing a pivotal role in the data analytics process: Data Sources:   Power BI connects to a wide range of data sources, including databases, cloud services, Excel files, web services, and more. This versatility enables organizations to consolidate their data from various systems into a single dashboard. Data Transformation:   Once the data is sourced, it undergoes transformation and cleaning processes to make it suitable for analysis. Power BI's Power Query Editor provides a user-friendly interface to manipulate, filter, and shape data according to specific requirements. Data Model:   The heart of Power BI's architecture lies in its data model, whic...

TOUCH PLATE BASED DOOR BELL

Title:  Touch plate based door bell  Circuit:  Components: IC 555 Resistors: 1 M, 100k, 330 ohms Transistor: BC547  PN2222A Capacitor: 10n 1 Copper plate : as touch plate. A 6v battery An LED / Ic UM66 Description: This is the simple circuit for touch plate based security system. In this project what basically done is, circuit detects stray voltages produced by mains voltage and electrostatic built  up in the room.If sufficient static voltage is detected by the plate then chip will charge up. Transistor BC 547 or PN2222A is used basically to increase the sensitivity.In place of led just connect IC um 66(melody IC). Applications: In homes, of course. This can be specially used in places like hospitals, when patients need to call doctor by himself.