Computer Programming C: UNIT II: Arrays and Strings

Arrays and Strings of C Program: 2 Marks Definitions Answers

Computer Programming C

Computer Programming C: Arrays and Strings: 2 Marks Definitions Answers, Multiple Choice Questions

2 Marks Definitions Answers

 

• An array is a collection of similar data items, that are stored under a common name. A value in an array is identified by index or subscript enclosed in square brackets with array name.

 

• Arrays can be classified into

 

• One‒Dimensional • Two‒Dimensional • Multi‒Dimensional

 

One‒Dimensional arrays: The collection of data items can be stored under a one variable name using only one subscript, such a variable is called the one‒dimensional array.

 

• The array can be initialized in the following two ways  i) At compile time ii) At run time char

 

Two dimensional arrays are used in situation where a table of values needs to be stored in an array. These can be defined in the same fashion as in one dimensional arrays, except a separate pair of square brackets are required for each subscript.

 

A String is a collection of characters. A string constant is a one dimensional array of characters terminated by a null ('\0') character.

 

• 'C' language allows multidimensional arrays. The dimension with three or more called multi dimensional arrays.

 

• In 'C' language the group of character, digits, and symbols enclosed within quotation marks are called as string otherwise strings are array of characters. Null character ('\0') is used to mark the end of the string.

 

• The '%s' control string can be used in scanf() statement to read a string from the terminal and the same may be used to write string to the terminal in printf() statement.

 

• The strlen() function: This function is used to count and return the number of characters present in a string.

 

• The strcpy() function: This function is used to copy the contents of one string to another and it almost works like string assignment operator.

 

• The strcat() function: The strcat() function is used to concatenate or combine, two strings together and forms a new concatenated string.

 

• The strcmp() function: This is a function which compares two strings to find out whether they are same or different.

 

• The strrev() function: The strrev() function is used to reverse a string.

 

Enumerated data types: The programmers can create their own data type and define what values the variables of these data types can hold.

 

• Matrices can be multiplied only when column of matrix A is equal to row of matrix B, otherwise multiplication is not possible.

 

• The inverse matrix of A can be denoted by A‒1.

 

• Transport of a matrix can be defined as the rows of a matrix A can be written as column of transport matrix and columns of matrix A can be written on rows of transport matrix, it can be denoted as AT.

 

• An array is a collection of similar data items, that are stored under a common name. A value in an array is identified by index or subscript enclosed in square brackets with array name.

 

Sequential Search is a search for data that compares each item in a list, one after the other.

 

Binary Search: The desired key is compared to the data in the middle of a sequential index or in the middle of a sequential file. The half that contains the data is then compared in the middle, and so on, until the key is located or the key is not found.

 

Selection Sort starts by comparing the entire list for the lowest item and moves it to the #1 position. It then compares the rest of the list for the next‒ lowest item and places it in the #2 position and so on until all items are in the required order. Selection sorts perform numerous comparisons, but fewer data movements than other methods.

 

Insertion Sort scans the sorted list, starting at the beginning, for the correct insertion point for each of the items from the unsorted list. Similar to the way people manually sort items, an insertion sort is not efficient for large lists, but is relatively fast for adding a small number of new items periodically.

 

• Merge Sort sequences data by continuously merging items in the list. Every single item in the original unordered list is merged with another, creating groups of two. Every two item group is merged, creating groups of four and so on until there is one ordered list.

 

• Quick Sort: One element, x of the list to be sorted is chosen and the other elements are split into those elements less than x and those greater than or equal to x. These two lists are then sorted recursively using the same algorithm until there is only one element in each list, at which point the sublists are recursively recombined in order yielding the sorted list.

 

• Bubble Sort starts by comparing the first item to the second, the second to the third and so on until it finds one item out of order. It then swaps the two items and starts over. The sort may alternate from the top of the list to the bottom and then from the bottom to the top. The name comes from the notion that items are raised or "bubbled up" to the top.

 

 

MULTIPLE CHOICE QUESTIONS

 

1. In C, if you pass an array as an argument to a function, what actually gets passed?

A. Value of elements in array

B. First element of the array

C. Base address of the array

D. Address of the last element of array

 

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

A. strinit()

B. strnset()

C. strset()

D. strcset()

 

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

B. 1

C. 0

D. Yes

 

4. How will you print \n on the screen?

A. printf("\n");

B. echo "\\n";

C. printf('\n');

D. printf("\\n");

 

5. The library function used to find the last occurrence of a char in a string is

A. strnstr()

B. laststr()

C. strrchr()

D. strstr()

 

6. Which of the following function is used to find the first occurrence of a given string in another string?

A. strchr()

B. strrchr()

C. strstr()

D. strnset()

 

7. Comment on the following statement: int(*a)[7];

A. An array "a" of pointers.

B. A pointer “a” to an array.

C. A ragged array.

D. None of the mentioned

 

8. Which of the following is not possible statically in C?

A. Jagged Array

B. Rectangular Array

C. Cuboidal Array

D. Multidimensional Array

 

9. 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 compiler would report an error.

B. The program may crash if some important data gets overwritten.

C. The array size would appropriately grow.

D. The element will be set to 0.

 

10. What does the following declaration mean? int (*ptr)[10];

A. ptr is a pointer to an array of 10 integers

B. ptr is array of pointers to 10 integers

C. ptr is an array of 10 integers

D. ptr is an pointer to array

 

11. The index or subscript value for an array of size n ranges from

A. 1 to n‒1

B. 0 to n‒1

C. 1 to n

D. 0 to n

 

12. Two dimensional array elements are stored.

A. System dependent

B. In row major dependent.

C. Compiler dependent

D. In column major dependent.

 

13. Array elements are stored in

A. Sequential memory locations

B. Scattered memory locations.

C. Direct memory locations

D. Random memory locations.

 

14. Identify the incorrect declaration of arrays from the following

A. int a[50];

B. float values[10][20];

C. double a[50];

D. int score[10,15];

 

15. Array is used to represent the following

A. A list of data items of different data types.

B. A list of data items of real data type.

C. A list of data items of same data type.

D. A list of data items of integer data type.

 

16. Arrays are passed to a function arguments by

A. Value

B. Reference

C. both value & reference

D. none of the above

 

17. An array a[8] will store how many values?

A. 8

B. 7.

C. 9

D.0

 

18. If an array is declared as a[10], then its elements will be stored as

A. a[1] to a[10]

B. a[1] to a[9]

C. a[0] to a[9]

D. a[0] to a[10]

 

19. If an array is declared as int a[4]= {3, 0, 1, 2};

Then values assigned to a[0] & a[4] will be

A. 3, 2

B. 0, 2

B. 3,0

D. 0, 4

 

20. Set of values of the same type, which has a single name followed by an index is called

A. Function

B. Structure

C. Array

D. Union

 

21. An array of pointers is same as

A. Pointer to array

B. Pointers to pointers

C. Pointer to function

D. Pointer to structure

 

22. If an array is used as function argument, the array is passed

A. By value

B. By reference

C. By name

D. The array cannot be used as a function argument.

 

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

A. printf();

B. scanf();

C. gets0;

D. puts();

 

 

TRUE FALSE

 

1. A pointer to a block of memory is effectively same as an array

True/False

2. Does this mentioning array name gives the base address in all the contexts?

True/False

3. Is there any difference in tthe following declarations?

int fun(int arr[]);

int fun(int arr[2]);

True/False

4. Are the expressions arr and &arr same for an array of 10 integers?

True/False

5. For the following statements will arr[3] and ptr[3] fetch the same character?

char arr[] = "VRB";

char *ptr = "VRB";

True/False

6. Is there any difference between the two statements?

char *ch = "VRB";

char ch = "VRB";

True/False

7. Will the program compile successfully?

#include <stdio.h>

int main()

{

char all = "VRB";

char *p = "MUNI";

a = "VRB";

P =  "PUBLISHERS";

printf("%s %s\n", a, p);

}

True/False

8. When an array is partially initialized, the rest of its elements will automatically be set to zero.

True/False

9. The whole array can be passed to a function. However, it can't be changed by the code in that function.

True/False

10. A two‒dimensional array represents data in the form of table with rows and columns.

True/False

 

Computer Programming C: UNIT II: Arrays and Strings : Tag: Computer Science : Computer Programming C - Arrays and Strings of C Program: 2 Marks Definitions Answers


Computer Programming C: UNIT II: Arrays and Strings



Under Subject


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation