Free Online Tutorials ==>> Machine Learning || Python Programming || DBMS || OOPs using C++ || DSA || Java Programming || Linux/Unix || C Programming
Go to your University || Python Lab || DSA Lab || AI & Machine Learning Lab || Linux Lab || OOPs Lab || DBMS Lab || JAVA Lab ||| Free Online Tutorials ||| 
companies for Campus Placement || Logical Reasoning || Quantitative Aptitude || General English || Technical-MCQ and Interview Questions || HR Interview Questions
0 like 0 dislike
29 views

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.8k points)
 
Best answer
Accessing array values is generally done through square brackets:

int val;

int array[10];

/* Setting the value of the fifth element to 5: */

array[4] = 5;

/* The above is equal to: */

*(array + 4) = 5;

/* Reading the value of the fifth element: */

val = array[4];

As a side effect of the operands to the + operator being exchangeable (--> commutative law) the following is equivalent:

*(array + 4) = 5;

*(4 + array) = 5;

so as well the next statements are equivalent:

array[4] = 5;

4[array] = 5;                            /* Weird but valid C ... */

and those two as well:

val = array[4];

val = 4[array];                         /* Weird but valid C ... */

C doesn't perform any boundary checks, accessing contents outside of the declared array is undefined (Accessing memory beyond allocated chunk ):

int val;

int array[10];

array[4] = 5;    /* ok */

val = array[4];  /* ok */

array[19] = 20;  /* undefined behavior */

val = array[15]; /* undefined behavior */
  Realize your learning potential with courses starting at ₹ 420
 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Online Free Training:  MACHINE LEARNINGPython Programming | Database Management System(DBMS) | Object Oriented Programming(OOPs) using C++ | Data Structures and Algorithms(DSA) | Java Programming | Linux/Unix | C Programming
Exams: List of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG) | JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Goeduhub
About Us | Contact Us   Social::   |  | 
...