Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 5 MCQs Introduction to Arrays

CAP1008 — C Programming 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 declaring arrays in C Easy

    Which of the following is the correct way to declare an integer array of size 10 in C?

  2. Question 2 of 60 declaring arrays in C Easy

    In C, what is the index of the first element of an array?

  3. Question 3 of 60 declaring arrays in C Easy

    For an array declared as int a[5];, what is the valid range of indices?

  4. Question 4 of 60 defining and processing 1d and 2d arrays Easy

    Which statement correctly initializes a 1D array at the time of declaration?

  5. Question 5 of 60 defining and processing 1d and 2d arrays Easy

    How is an element in a 2D array m accessed at row i and column j?

  6. Question 6 of 60 defining and processing 1d and 2d arrays Easy

    How many elements can be stored in an array declared as int a[3][4];?

  7. Question 7 of 60 defining and processing 1d and 2d arrays Easy

    Which loop is most commonly used to process all elements of a 1D array?

  8. Question 8 of 60 array applications: sorting and searching Easy

    Which searching technique checks each element of an array one by one?

  9. Question 9 of 60 array applications: sorting and searching Easy

    Binary search requires the array to be:

  10. Question 10 of 60 array applications: sorting and searching Easy

    Which of the following is a sorting algorithm?

  11. Question 11 of 60 character arrays Easy

    In C, a string is typically stored using which type of array?

  12. Question 12 of 60 character arrays Easy

    Which character marks the end of a string stored in a character array?

  13. Question 13 of 60 declaration and initialization of string Easy

    How many bytes are needed to store the string "Hi" in a character array?

  14. Question 14 of 60 declaration and initialization of string Easy

    Which of the following correctly initializes a string in C?

  15. Question 15 of 60 string handling functions Easy

    Which function is used to find the length of a string in C?

  16. Question 16 of 60 string handling functions Easy

    Which function is used to copy one string into another?

  17. Question 17 of 60 string handling functions Easy

    Which header file must be included to use string handling functions like strcat()?

  18. Question 18 of 60 structure and union: declaration, definition and initialization Easy

    Which keyword is used to define a structure in C?

  19. Question 19 of 60 structure and union: declaration, definition and initialization Easy

    In a union, all members share:

  20. Question 20 of 60 structure and union: declaration, definition and initialization Easy

    Which operator is used to access a member of a structure variable?

  21. Question 21 of 60 declaring arrays in C Medium

    What is the total number of bytes allocated for the array declared as int arr[10]; on a system where sizeof(int) is 4?

  22. Question 22 of 60 declaring arrays in C Medium

    Which of the following array declarations is invalid in standard C?

  23. Question 23 of 60 defining and processing 1d and 2d arrays Medium

    Given int a[5] = {1, 2, 3};, what are the values of a[3] and a[4]?

  24. Question 24 of 60 defining and processing 1d and 2d arrays Medium

    For a 2D array declared as int m[3][4]; stored in row-major order, what is the offset (in elements) of m[2][1] from the start of the array?

  25. Question 25 of 60 defining and processing 1d and 2d arrays Medium

    What does the following loop print?

    C
    int a[4] = {2, 4, 6, 8};
    int s = 0;
    for (int i = 0; i < 4; i++)
        s += a[i];
    printf("%d", s);

  26. Question 26 of 60 defining and processing 1d and 2d arrays Medium

    Which initialization correctly creates a 2D array with 2 rows and 3 columns, all initialized to zero?

  27. Question 27 of 60 array applications: sorting and searching Medium

    In a single pass of Bubble Sort (ascending) over the array {5, 1, 4, 2}, what is the array after the first complete pass?

  28. Question 28 of 60 array applications: sorting and searching Medium

    Binary search requires that the array is sorted. On the sorted array {2, 5, 8, 12, 16, 23}, how many comparisons are needed to find (comparing the middle element each time)?

  29. Question 29 of 60 array applications: sorting and searching Medium

    What is the worst-case time complexity of linear search on an array of elements?

  30. Question 30 of 60 array applications: sorting and searching Medium

    In Selection Sort (ascending) applied to {29, 10, 14, 37, 13}, what is the array after the first pass?

  31. Question 31 of 60 character arrays Medium

    How many bytes must a character array reserve to safely store the string "HELLO"?

  32. Question 32 of 60 character arrays Medium

    What does the following code print?

    C
    char c[] = {'C', 'O', 'D', 'E'};
    printf("%d", sizeof(c));

  33. Question 33 of 60 declaration and initialization of string Medium

    Which of the following correctly declares and initializes a string in C?

  34. Question 34 of 60 declaration and initialization of string Medium

    What is sizeof(str) for char str[] = "India";?

  35. Question 35 of 60 string handling functions Medium

    What value does strcmp("apple", "apple") return?

  36. Question 36 of 60 string handling functions Medium

    After executing the following code, what is stored in dest?

    C
    char dest[20] = "Good";
    strcat(dest, "Day");

  37. Question 37 of 60 string handling functions Medium

    What does strlen("Program\0ming") return?

  38. Question 38 of 60 structure and union: declaration, definition and initialization Medium

    Consider struct P { char c; int x; double d; };. On a typical system with 4-byte int, 8-byte double, and standard alignment, what is the most likely value of sizeof(struct P)?

  39. Question 39 of 60 structure and union: declaration, definition and initialization Medium

    For union U { int i; char c; };, what is sizeof(union U) on a system with 4-byte int?

  40. Question 40 of 60 structure and union: declaration, definition and initialization Medium

    What does the following code print?

    C
    struct Pt { int x, y; };
    struct Pt p = {3, 7};
    printf("%d", p.x + p.y);

  41. Question 41 of 60 declaring arrays in C Hard

    Consider the declaration int arr[5] = {1, 2};. What are the values of arr[2], arr[3], and arr[4]?

  42. Question 42 of 60 declaring arrays in C Hard

    Which of the following declarations is invalid in standard C89 (ANSI C)?

  43. Question 43 of 60 defining and processing 1d and 2d arrays Hard

    Given int a[3][4];, if the base address is 1000 and sizeof(int) is 4, what is the address of a[2][3] using row-major order?

  44. Question 44 of 60 defining and processing 1d and 2d arrays Hard

    What does the expression *(*(arr + 1) + 2) evaluate to for a 2D array arr?

  45. Question 45 of 60 defining and processing 1d and 2d arrays Hard

    In int a[] = {10, 20, 30, 40, 50};, what is the value of *(a + 3) - *a?

  46. Question 46 of 60 array applications: sorting and searching Hard

    During a single pass of bubble sort (ascending) on [5, 1, 4, 2, 8], what is the array state after the first complete pass?

  47. Question 47 of 60 array applications: sorting and searching Hard

    For binary search on a sorted array of 1000 elements, what is the maximum number of comparisons needed in the worst case?

  48. Question 48 of 60 array applications: sorting and searching Hard

    Which condition must hold for binary search to work correctly, and what happens if it is violated?

  49. Question 49 of 60 character arrays Hard

    What is the value of sizeof(str) for char str[] = "Hello";?

  50. Question 50 of 60 character arrays Hard

    Given char arr[5] = {'H', 'e', 'l', 'l', 'o'};, what happens when you pass arr to printf("%s", arr);?

  51. Question 51 of 60 declaration and initialization of string Hard

    What is the key difference between char *s = "Hello"; and char s[] = "Hello";?

  52. Question 52 of 60 declaration and initialization of string Hard

    For char str[10] = "Hi";, what are the contents of str[2] through str[9]?

  53. Question 53 of 60 string handling functions Hard

    What is the result of strlen(str) after executing char str[20] = "abc"; str[1] = '\0';?

  54. Question 54 of 60 string handling functions Hard

    Given char s1[10] = "abc", s2[] = "abd";, what does strcmp(s1, s2) return?

  55. Question 55 of 60 string handling functions Hard

    What is the danger of using strcat(dest, src) when dest was declared as char dest[6] = "Hi"; and src is "World"?

  56. Question 56 of 60 structure and union: declaration, definition and initialization Hard

    Consider struct P { char c; int i; double d; };. On a system with 4-byte int, 8-byte double, and standard alignment, what is the likely sizeof(struct P)?

  57. Question 57 of 60 structure and union: declaration, definition and initialization Hard

    Given union U { int i; char c[4]; }; on a little-endian system, after union U u; u.i = 1;, what is u.c[0]?

  58. Question 58 of 60 structure and union: declaration, definition and initialization Hard

    What is sizeof a union union U { int i; char c[10]; double d; }; on a system with 4-byte int, 8-byte double?

  59. Question 59 of 60 structure and union: declaration, definition and initialization Hard

    Which statement about initializing a structure with struct Point p = {.y = 5, .x = 3}; (designated initializers) is correct?

  60. Question 60 of 60 defining and processing 1d and 2d arrays Hard

    Given int a[2][3] = {1, 2, 3, 4, 5, 6};, what is the value of a[1][0]?

That's unit 5

Answer a few questions and your score shows up here.