MSBTE I Scheme CM/IF Branch Practice MCQs of “Programming In C (22226)” UNIT-4. Array and Strings

 

MSBTE I Scheme CM/IF Branch Practice MCQs of “Programming In C (22226)”

 

UNIT-4. Array and Strings

 

1. What is the maximun number of dimensions an array in C may have?

A. Two
B. eight
C. sixteen
D. Theoratically no limit. The only practical limits are memory size and compilers

Ans : D

 

2. A one dimensional array A has indices 1....75. Each element is a string and takes up three memory words. The array is stored at location 1120 decimal. The starting address of A[49] is

A. 1264
B. 1164
C. 1167
D. 1267

Ans : A

3. What will be the address of the arr[2][3] if arr is a 2-D long array of 4 rows and 5 columns and starting address of the array is 2000?

A. 2048
B. 2056
C. 2052
D. 2042

Ans : C

4. Array can be considered as set of elements stored in consecutive memory locations but having __________.

A. Same data type
B. Different data type
C. Same scope
D. None of these

Ans : A

5. Array is an example of _______ type memory allocation.

A. Compile time
B. Run time
C. Both A and B
D. None of the above

Ans : A

6. Size of the array need not be specified, when

A. Initialization is a part of definition
B. It is a formal parameter
C. It is a declaratrion
D. All of the above

Ans : A

7. The information about an array used in program will be stored in

A. Symbol Table
B. Activation Record
C. Dope Vector
D. Both A and B

Ans : C

8. The parameter passing mechanism for an array is

A. call by value
B. call by reference
C. call by value-result
D. None of the above

Ans : B

9. A string that is a formal parameter can be declared

A. An array with empty braces
B. A pointer to character
C. Both A and B
D. None of the above

Ans : C

10. Which of the following function is more appropriate for reading in a multi-word string?

A. scanf()
B. printf()
C. gets()
D. puts()

Ans : C

11. Length of the string "letsfindcourse" is

A. 13
B. 14
C. 15
D. 12

Ans : B

12. How will you print on the screen?

A. printf(" ");
B. printf(' ');
C. printf("\n");
D. printf("" ")

Ans : C

13. If the two strings are identical, then strcmp() function returns

A. -1
B. 1
C. 0
D. None

Ans : C

14. Which of the following statements are correct ?
1: A string is a collection of characters terminated by '.
2: The format specifier %s is used to print a string.
3: The length of the string can be obtained by strlen().
4: The pointer CANNOT work on string.

A. 1,2,3
B. 1,2
C. 2,4
D. 3,4

Ans : A

15. Let x be an array.Which of the following operations is illegal?
i) ++x.
ii) x+1.
iii) x++.
iv) x*2.

A. I and II
B. I, III and IV
C. III and IV
D. II and III

Ans : D

16. Strcat function adds null character

A. Only if there is space
B. Always
C. Depends on the standard
D. epends on the compiler

Ans : B

17. Which of the following function sets first n characters of a string to a given character?

A. strset()
B. strnset()
C. strcset()
D. strinit()

Ans : B

18. The library function used to find the last occurrence of a character in a string is

A. strnstr()
B. laststr()
C. strrchr()
D. strstr()

Ans : C



19. Which of the following gives the memory address of the first element in array foo, an array with 10 elements?

A. foo
B. &foo
C. foo[0]
D. &foo[0]

Ans : A

20. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash
D. None of the above

Ans : C

21. An array elements are always stored in ________ memory locations.?

A. Sequential
B. Random
C. Sequential and Random
D. None of the above

Ans : A

22. Let x be an array. Which of the following operations are illegal?
I. ++x
II. x+1
III. x++
IV. x*2

A. I and II
B. I, II and III
C. II and III
D. I, III and IV

Ans : D

23. What is the output of this program?

void main()

{

      int a[8] = {1,2,3,4,5};

      printf("%d", a[5]);

}

A. 5
B. 6
C. 0
D. Garbage Value

Ans : C

24. What is the output of this program?

void main()

{

      int arr[10];

      printf("%d %d", arr[-2], arr[11]);

}

A. 0 0
B. Garbage value 0
C. Garbage value Garbage value
D. Compilation Error

Ans : C

25. What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?

void main()

{

    int arr[2][2] = { 1, 2, 3, 4 };

    printf("%u, %u", arr+1, &arr+1);

}

A. 1004 1008
B. 1002 1008
C. 1002 1002
D. 1008 1002

Ans : A

26. What is the output of this program?

#include <stdio.h>

int main()

{

    int arr[5] = {1,2,3,4,5};

    int p, q, r;

    p = ++arr[1];

    q = arr[1]++;

    r = arr[p++];

    printf("%d, %d, %d", p, q, r);

    return 0;

}

A. 3 4 5
B. 3 4 4
C. 4 3 4
D. 4 4 5

Ans : C

27. What is the output of this program?
#include <stdio.h>

int main()

{

    int a[1]={100};

    printf("%d", 0[a]);

    return 0;

}

A. 100
B. 0
C. Garbage Value
D. Compilation Error

Ans : A

28. What is the output of this program? (Assume that base address of a is 1000 and size of integer is 32 bit)

int main()

{

    int a[10];

    a++;

    printf("%u", a);

    return 0;

}

A. 1004
B. 1002
C. 1008
D. Lvalue Required

Ans : D


29. Which of the following will print the value 2 for the above code?

#include <stdio.h>

int main()

{

    int arr[10][20][30] = {0};

    arr[3][2][1] = 2;

    return 0;

}

A. printf("%d",*(((a+3)+2)+1));
B. printf("%d",***((a+3)+2)+1);
C. printf("%d",*(*(*(a+3)+2)+1));
D. None of the above

Ans : C

 

30. Which is true about the given statment ?
int arr[10] = {0,1,2,[7]=7,8,9};

A. Compipation Error
B. Run-time Error
C. This is allowed in C
D. None of the above

Ans : C

31. What is the output of this program?

#include <stdio.h>

void main(){

char c[] = "GATE2011";

char *p =c;

printf("%s", p + p[3] - p[1]);

}

A. GATE2011
B. E2011
C. 2011
D. 11

Ans : C

32. What is the output of this program?

#include <stdio.h>

#include<string.h>

void main()

{

    char s1[20] = "Hello", s2[10] = " World";

    printf("%s", strcpy(s2, strcat(s1, s2)));

}

A. Hello World
B. HelloWorld
C. Hello
D. World

Ans : A

33. How many times the loop will execute ?

#include <stdio.h>

int main()

{

    char str[10] = "98765", *p;

    p = str + 1;

    *p = '0' ;

    printf ("%s", str);

}

A. 98
B. 0
C. 98766
D. 90765

Ans : D

 

34. What is the output of this program?

#include <stdio.h>

void main()

{

    char s[] = "Letsfindcourse";

    printf("%s", str);

}

A. Letsfindcourse
B. Letsfind
C. course
D. Compilation Error

Ans : B

35. What is the output of this program?

#include

int main()

{

    char str[14] = "Letsfindcourse";

    printf("%s", str);

    return 0;

}

A. Letsfindcours
B. Letsfindcourse
C. Run Time Error
D. Compilation Error

Ans : A

36. What is the output of the given code ?
#include <stdio.h>

int main()

{

    int i;

    char str[] = "";

    if(printf("%s", str))

        printf("Empty String");

    else

        printf("String is not empty");

    return 0;

}

A. Empty String
B. String is not empty
C. 0
D. None of the above

Ans : B

37. What is the output of this program?
#include <stdio.h>

int main()

{

    char str = "Hello";

    printf("%s", str);

    return 0;

}

A. Hello
B. Base address of str
C. Segmentation Fault
D. None of the above

Ans : C

38. What is the output of this program?
#include <stdio.h>

int main()

{

    char s1[] = "Hello";

    char s2[] = "Hello";

    if(s1 == s2)

        printf("Same");

    else

        printf("Not Same");

    return 0;

}

A. Not Same
B. Same
C. Compilation Error
D. None of the above

Ans : A

39. What will be the output of the program ?

#include <stdio.h>

int main(void)

{

    char p;

               char buf[10]={1,2,3,4,5,6,9,8};

    p=(buf+1)[5];

        printf("%d",p);

  

    return 0;

}

A. 5
B. 6
C. 9
D. None of the above

Ans : C

40. What will be the output of the program ?

#include <stdio.h>

int main()

{

   

               int a[5]={5,1,15,20,25};

    int i,j,m;

    i = ++a[1];

               j = a[1]++;

    m = a[i++];

               printf("%d, %d, %d", i, j, m);

  

    return 0;

}

A. 3,2,15
B. 2,3,20
C. 2,1,15
D. 1.2.5

Ans : A

 

 

 

 

loading...

Post a Comment

Previous Post Next Post