#include <stdio.h>
int main(int argc, char const *argv[]) {
/*
Okay so an actual practical example.
notice I only create 3 ints
but lets say i enter 4 as my input
then i will have used 4 extra numbers twice without
needing variable names.
All just memory magic baby!
WARNING: you may get a segmentation fault
but that doesnt actually impact the programs performace.
*/
int start;
int *ptr = &start;
int total = 0;
printf("how many numbers would you like to add: ");
scanf("%d", &start);
for (size_t i = 0; i < start; i++) {
ptr++;
printf("please enter a number: ");
scanf("%d", ptr);
total += *ptr;
}
printf("0");
for (size_t i = start; i > 0; i--) {
printf(" + %d", *ptr);
ptr--;
}
printf(" = %d\n", total);
return 0;
}
Comments
0 B
|👍
/👎