Logo/

Basic Programming: Array and String

Log in

Made with ScholarlyMake flashcards like these from your own notes

Basic Programming: Array and String

Questions and answers

12 cards
  1. Question:What is an array?

    Answer:An array is a data structure storing a fixed-size sequential collection of elements of the same type.

  2. Question:What is the definition of an array?

    Answer:A data structure storing a fixed-size sequential collection of elements of the same type.

  3. Question:How do you declare a 1-D array in C?

    Answer:int A[5];

  4. Question:How do you declare a 2-D array in C?

    Answer:int A[3][5];

  5. Question:How do you initialize an array in C?

    Answer:int A[5] = {1, 2, 3, 4, 5};

  6. Question:How do you access an element in a 1-D array in C?

    Answer:To access an element, you should define the array name and the location of the element in the array A[i].

  7. Question:How do you access an element in a 2-D array in C?

    Answer:To access an element, you should define the array name and two locations of the element in the array A[i][j].

  8. Question:What is the role of an array name in C?

    Answer:An array name is a pointer to the first element of the array.

  9. Question:What is a string in C?

    Answer:Strings are a sequence of characters in memory followed by the null character '\0'.

  10. Question:How do you initialize and print a string in C?

    Answer:Initialize a string like char text[] = "Hello World"; and print it with printf("%s", text);.

  11. Question:What is the fgets() function in C?

    Answer:The fgets() function reads at most one less than the number of characters specified by size from the given string and stores them in the string str.

  12. Question:What are some common string library functions in C?

    Answer:strlen(), strcpy(), strcat(), and strcmp().