Answers for "C print pointer"

C
1

how to print the address of a pointer in c

int a = 42;

printf("%pn", (void *) &a);
Posted by: Guest on July-03-2020
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:  %dn", *iptr );

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

/*Print the address of iptr itself*/
printf("Value:  %pn", &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
3

c printing char pointer

#include <stdio.h>

int main()
{
char * str = "Hello";
printf("%sn", str);

return 0;
}
Posted by: Guest on November-22-2020

Code answers related to "C"

Browse Popular Code Answers by Language