int x = 5;
int *ptr = &x;
printf("%d %d", *ptr, x);
*ptr dereferences the pointer to access the value at the address it points to, which is x = 5. So both *ptr and x print 5.
Both A and B are correct. Option A uses explicit type casting which is optional in C (not in C++). Option B avoids casting. Using sizeof(int) is preferred over hardcoding 4, as int size may vary across systems.
scanf() reads formatted input based on format specifiers and stops at whitespace. gets() reads a string until a newline is encountered. Note: gets() is deprecated due to buffer overflow vulnerabilities.
int x = 5;
int y = ++x + x++;
printf("%d", y);
This code exhibits undefined behavior because x is modified twice between sequence points without an intervening sequence point. The result depends on the compiler's implementation.
strlen() returns the length of a string without counting the null terminator ('\0'). For example, strlen("hello") returns 5, not 6.
int a = 10, b = 20;
int c = (a > b) ? a : b;
printf("%d", c);
The ternary operator (condition ? true_value : false_value) evaluates the condition (a > b). Since 10 is not greater than 20, it returns b which is 20.
void is used in two contexts: (1) as a function return type when a function doesn't return a value, and (2) to declare a generic pointer (void *) that can point to any data type.
char arr[10];
Each char occupies 1 byte in memory. An array of 10 chars will occupy 10 × 1 = 10 bytes.
In C, pointers are declared using the asterisk (*) symbol before the variable name. The syntax is 'datatype *pointer_name;'
int x = 5;
printf("%d", x++);
The post-increment operator (x++) returns the current value of x before incrementing. So printf prints 5, and then x becomes 6.