Recently, while skimming through udemy C-courses I learned something which never occured to me before, and also hadn’t read about:
It’s possible to declare an array of which the final size is not known at compile time, just by using the address of the *size*. Also, same course featured “a[i] can be written as i[a]”.
#include<stdio.h>
int main(){
int size = 0;
printf("Size of array: ");
scanf("%d",&size); //dynamically set size
int arr[size];
printf("ints one by one confirmed by ENTER:\n");
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
printf("Entered values: ");
for(int i = 0; i < size; i++)
{
printf(" %d", i[arr]); //i[arr] same as arr[i]!
}
}
🤯
Leave a Reply