Govt Exams
The break statement terminates the current loop or switch block and transfers control to the statement following the loop or switch. Without it, execution continues to the next case (fall-through).
malloc() is the standard C library function for dynamic memory allocation. It returns a void pointer to the allocated memory block, which can be cast to the required data type.
sizeof(arr) returns the total size of the array in bytes. An array of 5 integers, where each int is 4 bytes, equals 5 × 4 = 20 bytes.
The %d format specifier prints the ASCII value of the character. 'A' has ASCII value 65.
sizeof(arr) gives total size of array. sizeof(arr[0]) gives size of one element. Dividing gives the number of elements: 20/4 = 5.
All three functions can read strings, though gets() is deprecated due to security issues. fgets() is safer as it limits input size.
The void pointer is a generic pointer that can hold addresses of any data type. void is also used for functions returning nothing and parameters.
p points to arr, so p[5] is equivalent to *(p+5) which gives the value at arr[5].
The left shift operator (<<) shifts bits to the left by 1 position, which is equivalent to multiplying by 2. So 5 << 1 = 10.
int a = 5;
int b = ++a + a++;
printf("%d", b);
++a increments a to 6 and returns 6. Then a++ returns 6 and increments a to 7. So b = 6 + 6 = 12.