WorksheetsUNIT-3 Arrays Worksheet — Extracted Questions
Total questions: 54
Worksheet time: 27mins
Write a C-program to read and print array elements. Choose the option that correctly declares an integer array of size 10, reads 10 integers from standard input, and then prints them.
int a[10], i; for(i=0;i<10;i++){ scanf("%d", &a[i]); } for(i=0;i<10;i++){ printf("%4d", a[i]); }
int a[10], i; for(i=0;i<=10;i++){ scanf("%d", &a[i]); } for(i=0;i<=10;i++){ printf("%d", a[i]); }
int a[9], i; for(i=0;i<9;i++){ scanf("%d", &a[i]); } for(i=0;i<9;i++){ printf("%d", a[i]); }
int a[10], i; for(i=0;i<10;i++){ scanf("%d", &a); } for(i=0;i<10;i++){ printf("%d", &a[i]); }
Write a C-program to read and print your name. Which option matches the worksheet’s example that declares a character array and prints the stored name as a string?
char name[20]="vijaya"; printf("My name is : %s", name);
char name[5]="vijaya"; printf("My name is : %s", name);
char name[20]; scanf("%c", &name); printf("My name is : %c", name);
char name[20]="vijaya"; printf("My name is : %d", name);
Examples on Two-dimensional array — Read and print array elements using 2-D: Identify the task performed by the given C program with nested loops and scanf/printf around a 2×2 integer array.
Reads elements into a 2-D array and then prints all elements
Sorts the elements of a 2-D array in ascending order
Generates the first 10 Fibonacci numbers
Prints elements of a 1-D array in reverse order
Multidimensional arrays: According to the description, how does C conceptually view a three-dimensional array?
As an array of arrays of arrays
As a single continuous linked list
As a matrix of pointers to rows only
As a tree of nodes with child arrays
Multidimensional arrays: What term is used to describe the first dimension, which consists of rows and columns?
Plane
Row
Column
Layer
Declaring multidimensional arrays: For a fixed-length array declaration in C, what must be known at compilation time?
The size of each dimension must be a constant
The initial values for every element
The runtime input values
The memory addresses of all elements
Declaring multidimensional arrays: Which declaration matches the described syntax for a three-dimensional integer array named table?
int table[planes][rows][cols];
double table(rows, cols);
int table[rows][cols];
int table{planes, rows, cols};
Initialization: Given the example int table[3][5][4]={…}, what are the sizes of the three dimensions in order?
3, 5, 4
5, 4, 3
4, 5, 3
3, 4, 5
Finding number of words in a sentence: Identify the task performed by the program that reads a sentence and updates a counter before printing the result.
Counts the number of words in the sentence
Counts the number of characters in the sentence
Converts the sentence to uppercase
Reverses the sentence
Sample program printing Elements, Index, Address: What does the program print for each entered array element?
The element’s value, its index, and its memory address
Only the element’s value
Only the element’s memory address
The sum and average of all elements
Asending order: What ordering does the sorting program produce for the ten entered numbers?
Ascending order
Descending order
Random order
Original input order
Write C program to generate first 10 fibonacci numbers: What sequence does the program produce and print?
The first 10 Fibonacci numbers
The first 10 prime numbers
Factorials from 1 to 10
Squares of numbers from 1 to 10
Read array elements and print them into reverse order: After reading ten integers, what does the program output?
All elements in reverse order
All elements in ascending order
Only distinct elements
Only memory addresses of elements
Largest and smallest: From the ten entered integers, what does the program compute and print?
The largest and the smallest values
Only the average value
Only the sum of all values
The median value
String conversion with uppercase input: Given a string entered in uppercase, what transformation does the program apply to its alphabetical characters?
Converts uppercase letters to lowercase
Converts lowercase letters to uppercase
Reverses the entire string
Encrypts the string with a cipher
In C, a string is a variable‑length array of characters that is delimited by a specific character. What character terminates a C string?
A space
A newline
A tab
A null character
Why is a null character required at the end of a C string?
Because a string is stored as a logical data structure that needs a delimiter to mark its end
Because arrays in C cannot store spaces without an extra marker
Because C automatically appends a newline unless a null character is used
Because pointers cannot reference the last element
Which statement distinguishes a C string from a character array, as shown by H E L L O \0 versus H E L L O?
A character array must always contain digits
A C string is terminated by a null character, while a character array may not be
A character array cannot store uppercase letters
A C string cannot include spaces
Which of the following is a C string literal?
"Hello"
'H'
Hello (without quotes)
"H" (single quote)
According to the diagram of string concepts, how is Variable length categorized?
Only Fixed length
Length controlled and Delimited
Fixed length and Pointer
Delimited only
When implementing a fixed‑length string format, what is the first decision?
The delimiter to use
The size of the variable
The pointer type
The compiler version
In variable‑length strings, what is the main advantage stated?
They force a fixed buffer that prevents overflow
They allow using only the required memory, reducing wastage and data losses
They automatically convert to integers
They prevent the need for a null terminator
What do length‑controlled strings add?
A count specifying the number of characters in the string
A trailing newline
A leading tab
A second delimiter
In delimited strings, how is the end of the string identified?
By a count field
By a delimiter at the end
By a fixed array size
By a pointer cast
How can data be stored, according to Strings and characters?
Only as integers
As character literal or as string literal
Only as arrays of pointers
Only as double‑quoted text
Which quoting is used for a character literal versus a string literal?
Character literal uses double quotes; string literal uses single quotes
Character literal uses single quotes; string literal uses double quotes
Both use double quotes
Both use single quotes
Which declaration defines memory for a string as a local array?
char *pstr;
char str[9];
int str[9];
char **pstr;
What is noted about strings when initializing them as arrays or pointers?
Strings end with a newline
Strings end with a null character
Strings begin with a tab
Strings require numeric indexes only
Which two families provide formatted input and output of strings?
gets/fgets and puts/fputs
scanf/fscanf and printf/fprintf
read/write and open/close
strcpy/strcat and strlen
Which are special string‑only functions for input and output?
gets/fgets
puts/fputs
scanf/printf
read/write
What does the statement scanf("%s", str); accomplish?
Writes the contents of str to the screen
Reads a string from the keyboard into str
Converts str to uppercase
Allocates memory for str
What is described about gets()?
It reads characters until a newline and appends a null terminator; the newline is not added to the string
It reads only one character and returns it
It writes a string to the screen
It reads numeric input only
What is described about puts()?
It prints a string message to the output screen and can display the stored string in a variable
It reads a string from the keyboard
It compares two strings
It allocates a buffer
Which functions are listed as character input functions for reading a single character at a time from the keyboard?
getchar()
getche()
getch()
puts()
According to the description, what does getch() do?
Reads a character and echoes it on the screen
Reads the character from the keyboard and passes it immediately to the program with echoing on the screen
Reads a line into a buffer
Converts a character to uppercase
Which statement matches getchar()?
Accepts a character and displays the same character on the screen
Reads a character, assigns it to a variable, and stores it
Writes the stored character to the screen
Reads a string until a newline
What is described about getche()?
Accepts a character and passes it to the program while also echoing the same character on the screen
Reads a string without echo
Compares two characters
Allocates memory for a character
What is the role of putchar()?
To read a character from the keyboard
To print the stored character in a variable to the screen
To compare two characters
To convert characters to lowercase
Which standard C string library function determines the length of a string?
strcpy()
strlen()
strcmp()
strdup()
Which function compares two strings without discriminating between small and capital letters?
strcmp()
stricmp()
strlwr()
strdup()
Which function converts uppercase letters to lowercase letters?
strlwr()
strupr()
strcpy()
strlen()
Which function converts lowercase letters to uppercase letters?
strlwr()
strupr()
strncpy()
strcmp()
Which C library function returns the number of characters in a string as an integer?
strlen()
strcpy()
strcat()
strcmp()
In the syntax strcpy(stringvariable,stringvariable1), which position is the source string that contains the data to be copied?
First position
Second position
Both positions
Neither position
Which function is used to concatenate two strings, storing the combined result in the destination string?
strcat()
strcpy()
strcmp()
strrev()
The strcmp(stringvariable1,stringvariable2) function returns an integer. Which result indicates that both strings are equal?
Positive value
Negative value
Zero
Undefined
For strcmp(str1,str2), which sign of the return value indicates that str1 is greater than str2?
Positive
Negative
Zero
No return value
Which function is used to reverse a given string?
strrev()
strlwr()
strupr()
strcat()
Which function converts an uppercase string to lowercase?
strlwr()
strupr()
strrev()
strcmp()
Which function converts a lowercase string to uppercase?
strupr()
strlwr()
strrev()
strcat()
In the sample program that checks whether a string is a palindrome using strcpy, strrev, and strcmp, which value of i from i=strcmp(str,str1) indicates the string is a palindrome?
0
1
-1
A positive value
Which function is used to find the first occurrence of one string inside another string to determine whether a word is present?
strstr()
strchr()
strrchr()
strrev()
According to the listed functions, which one gives the last character of the given string?
strrchr()
strchr()
strspn()
strcat()
According to the listed functions, which one finds up to what length two strings are identical?
strspn()
strcmp()
strrchr()
strrev()
