InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
int main(){char p[] = "geeksquiz";char t;int i, j;for(i=0,j=strlen(p); i<j; i++){t = p[i];p[i] = p[j-i];p[j-i] = t;}printf("%s", p);return 0;}Output?(A) ziuqskeeg(B) Nothing is printed on the screen(C) geeksquiz(D) gggggggg |
| Answer» | |
| 2. |
Assume that a character takes 1 byte. Output of following program?#include<stdio.h>int main(){char str[20] = "GeeksQuiz";printf ("%d", sizeof(str));return 0;}(A) 9(B) 10(C) 20(D) Garbage Value |
| Answer» None | |
| 3. |
Predict the output of following program, assume that a character takes 1 byte and pointer takes 4 bytes.#include <stdio.h>int main(){char *str1 = "GeeksQuiz";char str2[] = "GeeksQuiz";printf("sizeof(str1) = %d, sizeof(str2) = %d",sizeof(str1), sizeof(str2));return 0;}(A) sizeof(str1) = 10, sizeof(str2) = 10(B) sizeof(str1) = 4, sizeof(str2) = 10(C) sizeof(str1) = 4, sizeof(str2) = 4(D) sizeof(str1) = 10, sizeof(str2) = 4 |
| Answer» | |
| 4. |
Output of following program#include <stdio.h>int fun(char *p){if (p == NULL || *p == '\0') return 0;int current = 1, i = 1;while (*(p+current)){if (p[current] != p[current-1]){p[i] = p[current];i++;}current++;}*(p+i)='\0';return i;}int main(){char str[] = "geeksskeeg";fun(str);puts(str);return 0;}(A) gekskeg(B) geeksskeeg(C) geeks(D) Garbage Values |
| Answer» | |
| 5. |
Output of following C program? Assume that all necessary header files are includedint main(){char *s1 = (char *)malloc(50);char *s2 = (char *)malloc(50);strcpy(s1, "Geeks");strcpy(s2, "Quiz");strcat(s1, s2);printf("%s", s1);return 0;}(A) GeeksQuiz(B) Geeks(C) Geeks Quiz(D) Quiz |
| Answer» | |
| 6. |
#include <stdio.h>void my_toUpper(char* str, int index){*(str + index) &= ~32;}int main(){char* arr = "geeksquiz";my_toUpper(arr, 0);my_toUpper(arr, 5);printf("%s", arr);return 0;}(A) GeeksQuiz(B) geeksquiz(C) Compiler dependent |
| Answer» | |
| 7. |
Predict the output of the following program:#include <stdio.h>int main(){char str[] = "%d %c", arr[] = "GeeksQuiz";printf(str, 0[arr], 2[arr + 3]);return 0;}(A) G Q(B) 71 81(C) 71 Q(D) Compile-time error |
| Answer» None | |
| 8. |
Consider the following code. The function myStrcat concatenates two strings. It appends all characters of b to end of a. So the expected output is “Geeks Quiz”. The program compiles fine but produces segmentation fault when run.#include <stdio.h>void myStrcat(char *a, char *b){int m = strlen(a);int n = strlen(b);int i;for (i = 0; i <= n; i++)a[m+i] = b[i];}int main(){char *str1 = "Geeks ";char *str2 = "Quiz";myStrcat(str1, str2);printf("%s ", str1);return 0;}Which of the following changes can correct the program so that it prints “Geeks Quiz”?(A) char *str1 = “Geeks “; can be changed to char str1[100] = “Geeks “;(B) char *str1 = “Geeks “; can be changed to char str1[100] = “Geeks “; and a line a[m+n-1] = ‘\0’ is added at the end of myStrcat(C) A line a[m+n-1] = ‘\0’ is added at the end of myStrcat(D) A line ‘a = (char *)malloc(sizeof(char)*(strlen(a) + strlen(b) + 1)) is added at the beginning of myStrcat() |
| Answer» | |
| 9. |
What does the following fragment of C-program print?char c[] = "GATE2011";char *p =c;printf("%s", p + p[3] - p[1]) ;(A) GATE2011(B) E2011(C) 2011(D) 011 |
| Answer» None | |
| 10. |
#include<stdio.h>int main(){char str[] = "GeeksQuiz";printf("%s %s %s\n", &str[5], &5[str], str+5);printf("%c %c %c\n", *(str+6), str[6], 6[str]);return 0;}(A) Runtime Error(B) Compiler Error(C) uiz uiz uizu u u(D) Quiz Quiz Quizu u u |
| Answer» | |
| 11. |
Consider the following C program segment:char p[20];char *s = "string";int length = strlen(s);int i;for (i = 0; i < length; i++)p[i] = s[length — i];printf("%s", p);The output of the program is? (GATE CS 2004)(A) gnirts(B) gnirt(C) string(D) no output is printed |
| Answer» | |
| 12. |
Predict the output?#include <stdio.h>int fun(char *str1){char *str2 = str1;while(*++str1);return (str1-str2);}int main(){char *str = "GeeksQuiz";printf("%d", fun(str));return 0;}(A) 10(B) 9(C) 8(D) Random Number |
| Answer» | |