

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Q1. How many times hello will be printed? int main(void) { int i,j,k; for(i=1; i<=4;i++) for(j=1;j<=i;j++) for(k=1;k<=j;k++) printf("hello\n"); return 0; } A) 4 B) 10 C) 20 D) 30 Q2. What is the output? int main(void) { char arr[][10] = {"Amit", "Suresh" , "John" , "Smith"}; char *ptr[4]; int i; for(i=0; i<=3; i++) ptr[i] = arr[3-i]; printf("%s,%s",ptr[0], arr[0]); return 0; } A) Smith,Amit B) Amit,Amit C) Smith,Smith D)Runtime error
arr[] begins at address 65686 and size of integer is of 4 bytes. int main(void) { int arr[] = {12, 14, 15, 23, 45}; printf("%u,%u",arr+1,&arr+1); return 0; } A) 65690, B) 65687, C) 65690 , D) 65690, Q4. What is the output? void main() { short int a=5; float b=10; short int p; p=&b; printf("%u\t",p); p++; printf("%u",p); } A) Compilation error B) The difference in printed addresses is sizeof(short int) C) The difference in printed addresses is sizeof(float) D) Segmentation fault run time error. Q5.What is the output? void fun(int x) { if(x>1) { fun(--x); printf("%d",x); fun(--x); } } void main() { fun (4); } A) 1231 B) 1321 C) 1234 D) 4321 Q6. What is the output? int main (void) { char c[] = "KATEWINCE"; char p =c; printf("%s", p+p[3]-p[1]) ; return (0); } A) INCE B) EWINCE C) WINCE D) None of the above Q7. What is the output? void main(void) { int i = 0; for(printf("A");printf("B");printf("C")) { for(printf("D");printf("E");printf("F")) break; if (i--) break; } } A) ABDECBFE B) ABDECBDE C) ADCBD D) Infinite Loop Q8 What is the output? int main() { union temp { int a, b;}; union temp t; t.a=100; t.b=200; printf("%d",t.a); return 0; } A) Compilation error B) 100 C) Run time error D) 200 Q 9. Consider the given program: If the given program is required to print the size of array arr[], which of the following two statements can be substituted in place of LINE1. S1: int temp = (char) ptr2 - (char) ptr1; S2: int temp = (ptr2 - ptr1) * sizeof(stu); A) Only S B) Only S C) Any one of S1 or S D) Neither S1, nor S typedef struct { int age; float marks; } stu; int main() { stu arr[5]; stu ptr1 = arr; stu ptr2 = ptr1 + 5; LINE printf ("%d",temp); } Q 10. Which of the following doesn’t require traversal** of elements in a linked list, given a pointer to the first node of the list? A) Deleting an element at the end of a singly linked list B) Deleting an element from the end of a linear doubly linked list. C) Inserting an element after the last element in a circular doubly linked list. D) Inserting an element at the end of a linear singly linked list. Q11. In C language, if precedence of + operator is higher than
Q1 5. What is the output? void main() { char *str = "BITS Pilani"; char *str1 = "BITS PILANI"; if (strcmp(str, str1)<0) printf("LOWER"); else printf("UPPER"); } A) Nothing is printed B) UPPER C) LOWER D) Compilation error
Q19. What is the output? int a, b, c = 0; void foo (void); void main () { static int a = 1; foo(); a += 1; foo(); printf ( "%d %d ", a,b) ; } (A) 3 1 4 1 4 2 (B) 4 2 6 1 6 1 (C) 4 2 6 2 2 0 (D) 3 1 5 2 5 2
Q1 6. What is the output? char writeBackward(char s[], int n) { if (n == 0) return '\0'; writeBackward(s, n--); printf ("%c",s[n]); } void main() { writeBackward("BITS PILANI",11); } A) BITS PILANI B) Compile time error C) INALIP STIB D) Run time error Q1 7. What is the output? int main() { int i,j,k; for(i=1;i<=3;i++) { if(i%2==0) k=2; else k=1; for(j=1;j<=i;j++,k+=2) printf("%d", k); } return 0; }
D) None of the above. Q1 8. Convert the following from base 6 to base 8: (524) 6 = (?) 8 A) 304 B) 104 C) 404 D) None of the above Q2 1. The following program intends to find the median (in variable t) of n sorted elements stored in array arr. What should be replaced in place of C and S to achieve the task? void main() { int n, i; float t; scanf("%d",&n); int arr[n]; //assume arr[] is initialized here. if (C) S else t = arr[n/2]; printf ("Median = %f",t); } A) C: n%2== S: t = (arr[n/2] + arr[n/2+1])/2.0; B) C: (2n)%2 == 0 S: t = (arr[n/2] + arr[n/2+1])/2.0; C) C: n%2== S: t = (arr[n/2] + arr[n/2-1])/2.0; D) C: (2n)%2 == 0 S: t = (arr[n/2] + arr[n/2-1])/2.0; Q 20. Select the correct choice. void main() { typedef struct { int age; char name; } stu; stu amit; amit.age = 18; //LIN strcpy (amit.name, "amit"); //LIN printf ("%s %d",amit.name,amit.age); } A) Program prints amit 18 B) If amit 18 if to be printed, replace LIN 2 with: amit.name = "amit"; C) If amit 18 is to be printed, insert the following after LIN1 and before LIN2: amit.name= (char)malloc(5*sizeof(char)); D) Both (B) and (C) above. void foo (void) { static int a = 2; int b = 1; a += ++b; printf ("%d %d ", a,b); }
best associated with the output of the following program. void main() { int i, j, rows; scanf("%d", &rows); for(i=1; i<=rows; i++) { for(j=1; j<=rows; j++) { if(i==1 || i==rows || j==1 || j==rows) printf("*"); else printf(" "); } //inner for loop printf("\n"); }//outer for loop } A) two vertical parallel lines B) two horizontal parallel lines C) hollow square D) hollow triangle