Search
 
SCRIPT & CODE EXAMPLE
 

C

pointer in c

#include <stdio.h>

int main()
{
    int j;
    int i;
    int *p; // declare pointer

    i = 7;
    p = &i; // The pointer now holds the address of i
    j = *p;

    printf("i = %d 
", i);  // value of i
    printf("j = %d 
", j);  // value of j
    printf("*p = %d 
", p); // the address held by the pointer

    *p = 32; // asigns value to i via the pointer

    printf("i = %d 
", i);   // value of i
    printf("j = %d 
", j);   // value of j
    printf("*p = %d 
", p);  // the address held by the pointer
    printf("&i = %d 
", &i); // address of i
  
  	return 0;
    }
Comment

how to make pointers in c

datatype *var;

variable var actually holds the address of the data(memory where it is stored)
*var lets you access the data stored at that address
Comment

struct pointer c

#include <stdio.h>
#include <stdlib.h>
struct person {
   int age;
   float weight;
   char name[30];
};

int main()
{
   struct person *ptr;
   int i, n;

   printf("Enter the number of persons: ");
   scanf("%d", &n);

   // allocating memory for n numbers of struct person
   ptr = (struct person*) malloc(n * sizeof(struct person));

   for(i = 0; i < n; ++i)
   {
       printf("Enter first name and age respectively: ");

       // To access members of 1st struct person,
       // ptr->name and ptr->age is used

       // To access members of 2nd struct person,
       // (ptr+1)->name and (ptr+1)->age is used
       scanf("%s %d", (ptr+i)->name, &(ptr+i)->age);
   }

   printf("Displaying Information:
");
   for(i = 0; i < n; ++i)
       printf("Name: %s	Age: %d
", (ptr+i)->name, (ptr+i)->age);

   return 0;
}
Comment

c structure with pointer

#include<stdio.h>
 
struct Point
{
   int x, y;
};
 
int main()
{
   struct Point p1 = {1, 2};
 
   // p2 is a pointer to structure p1
   struct Point *p2 = &p1;
 
   // Accessing structure members using structure pointer
   printf("%d %d", p2->x, p2->y);
   return 0;
}
Comment

pointer in C

#include <stdio.h>
int main()
{
   int* pc, c;
   
   c = 22;
   printf("Address of c: %p
", &c);
   printf("Value of c: %d

", c);  // 22
   
   pc = &c;
   printf("Address of pointer pc: %p
", pc);
   printf("Content of pointer pc: %d

", *pc); // 22
   
   c = 11;
   printf("Address of pointer pc: %p
", pc);
   printf("Content of pointer pc: %d

", *pc); // 11
   
   *pc = 2;
   printf("Address of c: %p
", &c);
   printf("Value of c: %d

", c); // 2
   return 0;
}
Comment

pointers c

#include <stdio.h>
int main()
{
   int *p;
   int var = 10;

   p= &var;

   printf("Value of variable var is: %d", var);
   printf("
Value of variable var is: %d", *p);
   printf("
Address of variable var is: %p", &var);
   printf("
Address of variable var is: %p", p);
   printf("
Address of pointer p is: %p", &p);
   return 0;
}
#output
#Value of variable var is: 10
#Value of variable var is: 10
#Address of variable var is: 0x7fff5ed98c4c
#Address of variable var is: 0x7fff5ed98c4c
#Address of pointer p is: 0x7fff5ed98c50

Comment

pointer in C

#include<stdio.h>
#include<stdlib.h>
main()
{
    int *p;
    p=(int*)calloc(3*sizeof(int));
    printf("Enter first number
");
    scanf("%d",p);
    printf("Enter second number
");
    scanf("%d",p+2);
    printf("%d%d",*p,*(p+2));
    free(p);
}
Comment

PREVIOUS NEXT
Code Example
C :: print only last 3 number float in c 
C :: refresh a chromebook terminal 
C :: yum install supervisor amazon linux 
C :: C Program to Check Whether Character is Lowercase or Not using islower function 
C :: c add char to char array 
C :: gitlab ci heroku 
C :: snprintf c 
C :: bool c++ 
C :: C special character display 
C :: C Input and Output Array Elements 
C :: Increment & Decrement Operator in C language 
C :: Example of read and write project in c 
C :: bp result system 
C :: c sjf 
C :: type cast in c 
C :: program in c to print 1 to 100 without using loop 
C :: how to find adam number uasing loop in C 
C :: create a gtk window 
C :: reset c array to zero 
C :: libreoffice reference cell in different sheet with sheet name with space 
C :: jock cranley 
C :: how to make an integer value equal to character 
C :: Chef in Vaccination Queue codechef solution in c++ 
C :: networkx remove attributes 
C :: how to know a type of a numbe in c 
C :: c multithreading sum from 0 to 1000 
C :: /usr/bin/mandb: fopen /var/cache/man/7935: Permission denied 
C :: take array input from user and calc the avr in c 
C :: split string at space C 
C :: arrays c 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =