pratiktest
11/8/2016 - 4:05 AM

coding.md

  • Array in C lvalue required
    #inlcude stdio.h
      int main(){
        int arr[5];
        arr++
      }
    
    
    • Note the arr+ will produce an error lvalue required
    • just arr decays to a pointer value, but there is no pointer object. its just a value. arr is just a value.
    • hence we need to assign it to something to manipulate the value
    • Think about int i = 5. i is a variable (an object that holds things) Also i+1 is a value, u cannot assign i+1 to anything since its a value and not an object
    • we cannot say i+1 =5. what we are doing is arr = arr+1. but arr is a value and not a pointer object
    • note printf("%p",arr) will give the address of first element
    • We can do this ...int* p = arr.... p++. P will keep on incrementing since its an object