Answers for "value of pointer in C"

C
4

pointer operators in c

&  ==> address operator
*  ==> dereference operator

// Example
int a = 1;
int *ptr; // int * defines a pointer variable pointing at an int
ptr = &a; // the address of 'a' is assigned to the pointer

// 'ptr' is now equal to the address of 'a'
// when dereferenced using *, it returns the value at that address

printf("value of a: %d", *ptr); // prints "value of a: 1"
Posted by: Guest on September-10-2021
4

how to print value of pointer in c

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

void pointerFuncA(int* iptr){
/*Print the value pointed to by iptr*/
printf("Value:  %d\n", *iptr );

/*Print the address pointed to by iptr*/
printf("Value:  %p\n", iptr );

/*Print the address of iptr itself*/
printf("Value:  %p\n", &iptr );
}

int main(){
int i = 1234; //Create a variable to get the address of
int* foo = &i; //Get the address of the variable named i and pass it to the integer pointer named foo
pointerFuncA(foo); //Pass foo to the function. See I removed void here because we are not declaring a function, but calling it.

return 0;
}
Posted by: Guest on July-03-2020

Code answers related to "C"

Browse Popular Code Answers by Language