summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorpankunull <panku_null@proton.me>2025-08-14 20:55:44 +0200
committerpankunull <panku_null@proton.me>2025-08-14 20:55:44 +0200
commitab79618ba19b920b7d55b0bad4d9665a15193bb7 (patch)
tree76d0b352a5bc5df7a6ed4d64cf44635c7dc31caa /main.c
parent27552efa93073b5a64dfa1cc82d110e98edb269f (diff)
added src code
Diffstat (limited to 'main.c')
-rw-r--r--main.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..30d5c61
--- /dev/null
+++ b/main.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+// Function that tries to change a number without pointer
+void noPointerChange(int num) {
+ num = 100; // Changes local copy only
+}
+
+// Function that changes a number using pointer
+void pointerChange(int *numPtr) {
+ *numPtr = 100; // Changes original value through pointer
+}
+
+int main() {
+ int value = 50;
+
+ printf("Before noPointerChange: %d\n", value);
+ noPointerChange(value);
+ printf("After noPointerChange: %d\n", value); // value unchanged
+
+ printf("Before pointerChange: %d\n", value);
+ pointerChange(&value);
+ printf("After pointerChange: %d\n", value); // value changed
+
+ return 0;
+}