|
CS 456 - Systems Programming
Spring 2024
|
Displaying ./code/jan18/print.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int num1 = 10;
printf("%d\n", num1); //prints num1
int *ptr = (int *) malloc(sizeof(int));
*ptr = 20;
printf("%p\n", ptr); //prints the address pointed to by the pointer
printf("%p\n", &ptr); /*prints the address of pointer -- extremely useful
when dealing with double pointers*/
printf("%d\n", *ptr); //prints the integer content of ptr
char *str = (char *) malloc(256 * sizeof(char));
strcpy(str, "Hello there!");
printf("%p\n", str); // print the address in the heap
printf("%s\n", str);
return 0;
}
|