Govt. Exams
Entrance Exams
int arr[5];
for(int i=0; i
Array values: arr[0]=0, arr[1]=1, arr[2]=4, arr[3]=9, arr[4]=16. Output is 1 4 16.
Linear search on unsorted array requires checking each element in worst case, giving O(n) time complexity.
char str[20];
strcpy(str, "Competitive");
strcat(str, " Exam");
printf("%s", str);
strcpy copies "Competitive" to str. strcat appends " Exam" to it, resulting in "Competitive Exam".
ptr[2] is equivalent to *(ptr+2), which points to the third element (index 2) of the array.
\0 is the null terminator which marks the end of a string. %s stops printing at the first null character.
int arr[] = {10, 20, 30};
printf("%d", sizeof(arr)/sizeof(arr[0]));
sizeof(arr) gives total bytes of array. sizeof(arr[0]) gives bytes of one element. Division gives number of elements: 3.
There is no standard library function for string reversal. strrev() is non-standard (available in some compilers). Manual reversal or custom functions are needed.
char[] creates a modifiable array with its own storage. char* points to read-only string literal in memory.
char str[] = "Code";
printf("%c", str[2]);
String "Code" has indices: C(0), o(1), d(2), e(3). str[2] refers to 'd'.
In C, arrays decay to pointers when passed to functions, meaning the address is passed. Any modifications through the pointer affect the original array. This is effectively pass-by-reference behavior for arrays.