#include<stdio.h> int main() { int i=10; int *j=&i; return 0; }
#include<stdio.h> int main() { int *j; void fun(int**); fun(&j); return 0; } void fun(int **k) { int a=10; /* Add a statement here */ }
#include<stdio.h> int main() { char s[] = "CuriousTab"; char t[25]; char *ps, *pt; ps = s; pt = t; while(*ps) *pt++ = *ps++; /* Add a statement here */ printf("%s\n", t); return 0; }
#include<stdio.h> int main() { int arr[3][3] = {1, 2, 3, 4}; printf("%d\n", *(*(*(arr)))); return 0; }
#include<stdio.h> #include<string.h> int main() { static char s[] = "Hello!"; printf("%d\n", *(s+strlen(s))); return 0; }
#include<stdio.h> #include<string.h> int main() { char str1[20] = "Hello", str2[20] = " World"; printf("%s\n", strcpy(str2, strcat(str1, str2))); return 0; }
Step 2: printf("%s\n", strcpy(str2, strcat(str1, str2)));
=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore str1 contains "Hello World".
=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable str2.
Hence it prints "Hello World".
#include<stdio.h> int main() { char str1[] = "Hello"; char str2[] = "Hello"; if(str1 == str2) printf("Equal\n"); else printf("Unequal\n"); return 0; }
Step 2: char str2[] = "Hello"; The variable str2 is declared as an array of characters and initialized with a string "Hello".
We have use strcmp(s1,s2) function to compare strings.
Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both variable is not same. Hence the if condition is failed.
Step 4: At the else part it prints "Unequal".
#include<stdio.h> #include<string.h> int main() { char str[] = "India\0\CURIOUSTAB\0"; printf("%d\n", strlen(str)); return 0; }
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".
#include<stdio.h> #include<string.h> int main() { char str[] = "India\0\CURIOUSTAB\0"; printf("%s\n", str); return 0; }
Step 1: char str[] = "India\0\CURIOUSTAB\0"; The variable str is declared as an array of characters and initialized with value "India"
Step 2: printf("%s\n", str); It prints the value of the str.
The output of the program is "India".
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.