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

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.

Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️

Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️ Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️ A load cell is a transducer that converts force (weight) into an electrical signal. The HX711 is a precision 24-bit analog-to-digital converter (ADC) designed for weigh scales. Today we’ll connect a load cell to Raspberry Pi 3 using the HX711 module. ЁЯзк ЁЯФз Components Required Component Quantity Raspberry Pi 3 1 Load Cell 1 HX711 Module 1 Jumper Wires 6 Breadboard (optional) 1 ЁЯФМ Pin Connections HX711 Pin Raspberry Pi Pin Pin Number VCC 5V Pin 2 GND Ground Pin 6 DT GPIO 5 Pin 29 SCK GPIO 6 Pin 31 Figure: Load Cell connected to Raspberry Pi 3 via HX711 ЁЯТ╗ Python Code from hx711 import HX711 import RPi.GPIO as GPIO import time hx = HX711(dout_pin=5, pd_sck_pin=6) hx.set_reading_format("MSB", "MSB") hx.set_reference_unit(1) hx.reset()...

Interfacing Sound Sensor with Raspberry Pi 3

ЁЯФ╣ Overview The KY-037 is a high-sensitivity sound detection sensor that can detect noise levels in the environment. It provides both analog and digital outputs. In this tutorial, we’ll interface the digital output of KY-037 with Raspberry Pi 3 Model B+ (without using an ADC like MCP3008) and detect sound events.