Answers for "c ** pointer"

C
1

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 n", i);  // value of i
    printf("j = %d n", j);  // value of j
    printf("*p = %d n", p); // the address held by the pointer

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

    printf("i = %d n", i);   // value of i
    printf("j = %d n", j);   // value of j
    printf("*p = %d n", p);  // the address held by the pointer
    printf("&i = %d n", &i); // address of i
  
  	return 0;
    }
Posted by: Guest on February-13-2022
0

pointer c

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *ptr, i , n1, n2;
    printf("Enter size: ");
    scanf("%d", &n1);

    ptr = (int*) malloc(n1 * sizeof(int));

    printf("Addresses of previously allocated memory: ");
    for(i = 0; i < n1; ++i)
         printf("%un",ptr + i);

    printf("nEnter the new size: ");
    scanf("%d", &n2);

    // rellocating the memory
    ptr = realloc(ptr, n2 * sizeof(int));

    printf("Addresses of newly allocated memory: ");
    for(i = 0; i < n2; ++i)
         printf("%un", ptr + i);
  
    free(ptr);

    return 0;
}
Posted by: Guest on June-18-2021
0

pointer in C

#include <stdio.h>
int main()
{
   int* pc, c;
   
   c = 22;
   printf("Address of c: %pn", &c);
   printf("Value of c: %dnn", c);  // 22
   
   pc = &c;
   printf("Address of pointer pc: %pn", pc);
   printf("Content of pointer pc: %dnn", *pc); // 22
   
   c = 11;
   printf("Address of pointer pc: %pn", pc);
   printf("Content of pointer pc: %dnn", *pc); // 11
   
   *pc = 2;
   printf("Address of c: %pn", &c);
   printf("Value of c: %dnn", c); // 2
   return 0;
}
Posted by: Guest on January-18-2022

Code answers related to "C"

Browse Popular Code Answers by Language