Govt Exams
This is a swap operation. Initially a=10, b=20. After temp=a (temp=10), a=b (a=20), b=temp (b=10). Output: 20 10.
malloc() (memory allocation) is used to dynamically allocate memory on the heap in C. It requires #include <stdlib.h>. new() is used in C++, not C.
The pre-increment operator (++x) increments x first, then assigns it. So x becomes 6, and y is assigned 6. Output: 6 6.
The do-while loop executes the loop body at least once before checking the condition. Other loops check the condition before execution. Syntax: do { } while(condition);
The operator += means x = x + 3. So x = 5 + 3 = 8. The printf statement outputs 8.
p is a pointer to x, so &x gives the address of x. *p (dereferencing) gives the value stored at that address, which is 5. The output will be 5.
strcmp() is the standard library function used to compare two strings. It returns 0 if strings are equal, negative if first string is less, and positive if first string is greater. It's declared in string.h.
Array indexing in C starts from 0. str[0]='H', str[1]='e', str[2]='l', str[3]='l', str[4]='o', str[5]='\0'. Therefore, str[1] is 'e'.
malloc() (memory allocation) is the standard function in C for dynamic memory allocation. It returns a void pointer to the allocated memory. The syntax is: ptr = (type*)malloc(size);
When %d format specifier is used with a char variable, it prints the ASCII value. The ASCII value of 'A' is 65. If it were 'a', the value would be 97.