Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(int argc, const char * argv[]) {
- printf("\n\n");
- // Code here
- int numberarray[5]; // Empty storage as slots don't have defined values.
- int *ptr = numberarray; // Starts at beginning of array rather than having to '&numberarray[0]'
- int value = 2;
- for(;ptr<&numberarray[5]; ptr++)
- /*The ';' is there because the for loop doesn'tneed initialisation as the pointer is already pointing to the beginning of the array. If 'ptr' hasn't reached the address of element 5 (Represented by the '&' symbol) in the array then increment ptr value by 1 after every loop until it reaches the non-existent address of element 5. Arrays start from 0,1,2,3,4 which is 5 elements. When it reaches element 5 which doesn't exist, the loop breaks. Incrementation is represented by 'ptr++'*/
- {
- *ptr = value; // Follow the pointer '*' and set it to value.
- value = value * 2; // After each loop, 'value' is worth *2 its original value.
- }
- int i;
- for(i=0;i<5;i++){
- printf("%d, ", numberarray[i]);
- if(i==4){
- printf(".");
- }
- }
- // End of code
- printf("\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment