From 5af4c707ebda9063a03acecd5ea8088ff934e46c Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Fri, 6 Oct 2023 15:24:41 +0100 Subject: [PATCH] c13 --- C13/ex2.c | 27 +++++++++++++++++++++++++++ C13/ex3.c | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 C13/ex2.c create mode 100644 C13/ex3.c diff --git a/C13/ex2.c b/C13/ex2.c new file mode 100644 index 0000000..1b7f012 --- /dev/null +++ b/C13/ex2.c @@ -0,0 +1,27 @@ +#include +#include + +int main (void ) +{ + // Declare a in integer + int c,d; + + // Declar and integer pointer + int *ptrC; + + // Some assgnments + c = 10; // C now contains the value 10 + ptrC = &c; // ptrC now 'Points' to c + + *ptrC = 20; + + // Get the value of c via the pointer and store in d + d = *ptrC; // d now contains 10 + printf ("The value in d is %d\n", d); + + // Change the value of c via the pointer ptrC + *ptrC = 1; //c now contains 1 + printf ("The value in c is %d\n", c); + + return 0; // exit +} diff --git a/C13/ex3.c b/C13/ex3.c new file mode 100644 index 0000000..7111359 --- /dev/null +++ b/C13/ex3.c @@ -0,0 +1,27 @@ +#include +#include + +int main (void ) +{ + // Declare a in integer + float c,d; + + // Declar and integer pointer + float *ptrC; + + // Some assgnments + c = 10; // C now contains the value 10 + ptrC = &c; // ptrC now 'Points' to c + + *ptrC = 20; + + // Get the value of c via the pointer and store in d + d = *ptrC; // d now contains 10 + printf ("The value in d is %f\n", d); + + // Change the value of c via the pointer ptrC + *ptrC = 1; //c now contains 1 + printf ("The value in c is %f\n", c); + + return 0; // exit +}