Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Strings Questions
sizeof an array of pointers and strlen of the first word: assume pointer size is 4 bytes. What does this print? #include
#include
int main() { char str[] = {'Frogs', 'Do', 'Not', 'Die', 'They', 'Croak!'}; printf('%d, %d', sizeof(str), strlen(str[0])); return 0; }
Modifying a char array then attempting to reassign it: what does this program do? #include
int main() { char str[] = 'Nagpur'; // writable array str[0] = 'K'; // modify first character → 'Kagpur' printf('%s, ', str); str = 'Kanpur'; // attempt to reassign an array variable printf('%s', str+1); return 0; }
Editing a printf format string in a writable array: what is printed? #include
int main() { char p[] = '%d '; // writable copy of the format p[1] = 'c'; // change '%d' to '%c' printf(p, 65); return 0; }
Pointer arithmetic on string literals with printf: what is printed? #include
int main() { printf(5 + 'Good Morning '); return 0; }
Copying a C string using pointer assignment in the while condition and again in the body: what final string is printed? #include
int main() { char str1[] = 'Hello'; char str2[10]; char *t, *s; s = str1; t = str2; while (*t = *s) *t++ = *s++; printf('%s ', str2); return 0; }
Type mismatch: attempting to store a string literal in a single char variable. What happens? #include
int main() { char str = 'CuriousTab'; // invalid: char cannot hold a whole string printf('%s ', str); return 0; }
Pointer arithmetic on string literals with printf: determine the output. #include
int main() { printf(5 + 'CuriousTab '); return 0; }
In C, what is the output of this string-library expression (concatenation + copy + compare)? #include
#include
int main() { static char str1[] = "dills"; static char str2[20]; static char str3[] = "Daffo"; int i; i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills"); printf("%d ", i); return 0; }
In C on a typical 32-bit model (char=1 byte, int=4 bytes, float=4 bytes), what does sizeof report? #include
int main() { char ch = 'A'; printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f)); return 0; }
In C string-pointer assignment sequencing, what prints? #include
int main() { char t; /* unused */ char *p1 = "India", p2; p2 = p1; / p2 points to "India" / p1 = "CURIOUSTAB";/ p1 now points elsewhere */ printf("%s %s ", p1, p2); return 0; }
In C, what is sizeof for this compound string with embedded nulls? #include
int main() { char str[] = "India\0CURIOUSTAB\0"; printf("%d ", sizeof(str)); return 0; }
In C, printf return value in an if-condition with an empty C-string literal element. #include
int main() { int i; char a[] = "\0"; /* a[0] == 0, array is a valid empty string */ if (printf("%s", a)) printf("The string is empty "); else printf("The string is not empty "); return 0; }
In C, basic strlen on a digit-only literal: what is printed? #include
#include
int main() { printf("%d ", strlen("123456")); return 0; }
In Turbo C (16-bit), what happens when you assign a string literal to a single char element? #include
int main() { char str[10] = "India"; str[6] = "CURIOUSTAB"; /* invalid: assigning char* to char / printf("%s ", str); return 0; }
In C, swapping function parameters passed by value (pointers to string literals): what prints? #include
void swap(char *, char *); int main() { char *pstr[2] = {"Hello", "CuriousTab"}; swap(pstr[0], pstr[1]); printf("%s %s", pstr[0], pstr[1]); return 0; } void swap(char *t1, char *t2) { char *t; t = t1; t1 = t2; t2 = t; }
In C, 2D array-of-strings indexing vs pointer arithmetic: what characters print? #include
int main() { static char mess[6][30] = { "Don't walk in front of me...", "I may not follow;", "Don't walk behind me...", "Just walk beside me...", "And be my friend." }; printf("%c, %c ", *(mess[2] + 9), ((mess + 2) + 9)); return 0; }
On a 16-bit Turbo C/DOS platform (int=2 bytes), what does sizeof report for these literals? #include
int main() { printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0)); return 0; }
In C programming on a 32-bit system (pointer size = 4 bytes), what will this program print for sizeof results of an array versus a pointer, and of the pointed elements? #include
int main() { char a[] = "Visual C++"; /* array holds characters plus the '\0' terminator */ char b = "Visual C++"; / pointer to string literal */ printf("%d, %d ", sizeof(a), sizeof(b)); printf("%d, %d", sizeof(*a), sizeof(*b)); return 0; }
In C programming, consider the fixed-size array below. Will this program compile and what would be printed if it did? #include
int main() { char str[7] = "CuriousTab"; /* literal length exceeds array capacity */ printf("%s ", str); return 0; }
1
2
3