int main() { int arr[] = {12, 13, 14, 15, 16}; printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0])); return 0; }
*ptr++ increments the pointer and not the value, ++*ptr increments the value being pointed by ptr .
Explanation
j=&i implies *j=i; *j=3 i**j=3*3=9 i**j*i=9*3=27 i**j*i+*j=27+3=30
int main()
{ printf(5+"Good Morning\n"); return 0; }
printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string. Hence the output is "Morning"
{
char str[] = "India\0\is Best\0";
printf("%d\n", strlen(str));
return 0;
}
The function strlen returns the number of characters in the given string. Therefore, strlen(str) becomes strlen("India") contains 5 characters. A string is a collection of characters terminated by '\0'. The output of the program is "5"
printf("%s ", s++ +3); -> ic since (s++ +3) and s++ is post increment but +3 just print string from 'i'. It ll not increment the pointer to 3. printf("%s",s); here after incrementing (s++) It ll print ''asic''.
int main() { char *str; str = "%s"; printf(str, "K\n"); return 0; }
printf(str, "K\n"); is replaced with printf("%s" , "K\n"); (since str = "%s";) So it will print K.
The function printf() returns the number of characters printed on the console. char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty. if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if condition is failed. In the else part it prints "The string is not empty".
char p[] = "%d\n"; The variable p is declared as an array of characters and initialized with string "%d". p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes "%c". printf(p, 65); becomes printf("%c", 65); Therefore it prints the ASCII value of 65. The output is 'A'.
char str1[] = "Hello";
char str2[] = "Hello";
if(str1 == str2)
printf("Equal\n");
else
printf("Unequal\n");
if(str1 == str2) here the address of str1 and str2 are compared. The addresses of both variables are not same. Hence the if condition is failed. At the else part it prints "Unequal".
Pointer always store integer value so cp will store the memory address of location where string "jack " is stored. vp = &ch; Will store address of ch in vp so while we print content in printf it will print asccii value of 74 i.e "J" vp = &j; It will assign address of j to vp again it will print ascii value of 65 as "A" vp = cp; In this step cp is pointing to memory locatioon where string jack is stored and we r incrementing it by two so it will point to "C" from sring "JACK" and since we hava given %S in printf so it will print content from c onward ie "CK"
*(b+1) = *(b+i)+5; 1. i = 0 => *(b+1) ie 4 is replaced by *(b+0)+5 ie 2+5 2. i = 1 => *(b+1) ie 4 is replaced by *(b+1)+5 ie 4+5 3. i = 2 => *(b+1) ie 4 is replaced by *(b+2)+5 ie 6+5 4. i = 3 => *(b+1) ie 4 is replaced by *(b+3)+5 ie 8+5 5. i = 4 => *(b+1) ie 4 is replaced by *(b+4)+5 ie 10+5
Quiz Review Timeline (Updated): Mar 21, 2022 +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.