ANSI C Programming: Text Processing

In a one-dimensional array, which month of the year is referenced by months[1]?

January
February
March
April
2 
 
Which of the following pieces of code defines a character variable named charray with 20 elements in its array?
%010char charray [20]
%010char charray [20];
%010char charray [19];
%010char charray [19]
|
2
Which of the following are reasons for declaring an array?
|
Choose more than one item.
|
So that the C compiler can carry out array-bound checking
So that the C compiler knows how large the array is
So that the C compiler knows how many variables are functioning
So that the C compiler knows the array type
|
2, 4
Which of the following lines of code defines a two-dimensional array named sales of type int having 12 rows and 2 columns?
%010int sales[12][2];
%010int sales[12 x 2];
%010int sales [2][12];
%010int sales [12][2]
|
1
 
 
Which of the following are used to enclose elements when an array is initialized?
[]
()
{}
<>
|
3
Which of the following are legal array initializations in ANSI C?
|
Choose more than one item.
|
%010int var[5] = {10,20,30,40};
%010int var[5] = {10,20,30,40,50};
%010int var[4] = {10,20,30,40,50};
%010int var[4] = {10,20,30,40,50,60};
|
1, 2
|
20
|
Correct.
|
5
What happens to all excess elements in the array if a static array has fewer initializing data objects than the subscript limit?
|
Choose an option.
|
They are set to zero
They are deleted
They are ignored
|
1
Which of the following types of array are initialized at run time?
|
Choose an option.
|
External
Auto
Static
|
2
|
15
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 020201t SXY Q,0,0,382,350
Which of the following lines of code passes the address of the sales array and the month variables arguments to the topmonth() function?
|
Choose an option.
|
%010num = sales(topmonth,month);
%010num = topmonth(month,sales)
%010num = topmonth(sales,month)
%010num = topmonth(sales,month);
|
4
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 020202t SXY Q,0,0,356,332
What do the square brackets of an array name contain  that is equivalent to the array name preceded by an asterisk?
|
Choose an option.
|
%010the max subscript of the array
0
1
%010the max subscript of the array less one
|
2
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 020203t SXY Q,0,0,350,349
Which of the following statements represents the address of the second element of an array called sales?
|
Choose an option.
|
%010sales[1]
&sales[1]
%010sales[2]
&sales[2]
|
2
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 020204t SXY Q,0,0,290,350
Which of the following is the correct address for the array sales?
|
Choose an option.
|
&sales
&sales[]
%010sales
%010sales[]
|
3
\
What datatype can be used as elements in an array to make a string, which is terminated by the first null character?
|
Choose an option.
|
The int dataype
The float datatype
The char datatype
The double datatype
|
3
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 030102t SXY Q,0,0,350,344
Which of the following is the correct definition and initialization of a simple character array?
|
Choose an option.
|
%010char arr[4] = {'Y','e','s','?'};
%010int arr[4] = {'Y','e','s','?'};
%010char arr[5] = 'Yes?';
%010char arr[5] = "Yes?\0";
%010char arr[5] = {'Y','e','s','?','\0'};
|
1
|
25
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 030103t MXY Q,0,0,394,358
Identify the true statements about this initialization:

char arr[24] = "Please enter username:\n";
|
Choose more than one item.
|
It's initializing a string literal
Element arr[14] is the letter u
It includes a newline
Element arr[23] is a null character
22 bytes are reserved in memory
|
1, 3, 4
|
25
|
Correct.
|
5
|
Partly right. The correct options are highlighted.
|
You have not made any correct choices. The correct options are highlighted.


@@QUES 030104t MXY Q,0,0,361,363
Which of the following statements about strings and string literals are true?
|
Choose more than one item.
|
Strings must be terminated with a null character
String literals must be terminated with a null character
String literals are more efficient than variable arrays
Strings are delimited by double quotes
|
1, 2
|
20
|
Correct.
|
5
|
Partly right. The correct options are highlighted.
|
You have not made any correct choices. The correct options are highlighted.


@@QUES 030201t SXY Q,0,0,465,365
The size of a string strng is defined by a symbolic constant, MAX_LEN, and there are two other strings, stgbegin and stglen, each of size 4. Identify the correct definition of the three one-dimensional arrays for these three strings.
|
Choose an option.
|
%010int strng[MAX_LEN], stgbegin[4], stglen[4];
%010char strng[MAX_LEN], stgbegin[4], stglen[4];
%010char strng[MAX_LEN][MAX_LEN], stgbegin[4], stglen[4];
%010char *strng[MAX_LEN], stgbegin[4], stglen[4];
|
2
|
20
|
 
 Which of the following lines of code returns a pointer to char?
|
Choose an option.
|
%010char *substr(char*, int, int);
%010char substr(char, int, int);
%010char substr(char*, int, int);
%010char substr(*char, int, int);
|
1
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 030203t SXY Q,0,0,473,350
A character array instring[50] is initialized to {'a','b','c','d','e','f'}, and in the main() function instring is assigned to the character pointer *cptr. Identify the problem with this line of code:

while(*cptr != NULL)
|
Choose an option.
|
NULL is an inappropriate operand
The pointer has been initialized incorrectly
There is no null character in instring
|
3
In an ANSI C program the user has been prompted to enter the start position of a substring. This will be read into a string stgbegin.

Which of the following lines of code does this?
|
Choose an option.
|
%010gets(stgbegin);
%010getstring(stgbegin);
%010geddit(stgbegin);
%010getchar(stgbegin);
|
1
|
A user input string, stgbegin, defined as a character array, has to be converted to an integer value in the variable begin. Identify the correct code to do this.
|
Choose an option.
|
%010begin = atof(stgbegin);
%010begin = getchar(stgbegin);
%010stgbegin = atol(begin);
%010begin = atoi(stgbegin);
|
4
Identify the true statements about the strlen() function.
|
Choose more than one item.
|
It determines the length of a string
It compares the lengths of two strings
It includes terminating null characters
It returns the number of characters in a string
A program using strlen() should have a string.h header file
|
1, 4, 5
|
Identify the true statements about the strcpy() function.
|
Choose more than one item.
|
It has three arguments
It copies the second string to the first
It overwrites the string it is copying into
It copies the first string to the second
Copying stops after the null character has been copied
|
2, 3, 5
|
25
|
Correct.
|
5
|
Partly right. The correct options are highlighted.
|
You have not made any correct choices. The correct options are highlighted.


@@QUES 030403t SXY Q,0,0,519,356
Which of the following is the correct definition of the strcmp() function?
|
Choose an option.
|
It tests two strings to see if the first is alphabetically less than, equal to, or greater than the second
It tests n characters of two strings to see if the second is alphabetically less than, equal to, or greater than the first
It copies the second string, including its terminating null character, into the first string
It tests n characters of two strings to see if the first is alphabetically less than, equal to, or greater than the second
|
1
Which library function compares a specified number of characters in two strings?
|
Choose an option.
|
%010strcat()
%010strcmp()
%010strncmp()
%010strcpy()
%010strlen()
|
3
|
25
|
Correct.
Which of the following is the correct definition of a pointer to a string called strptr?
|
Choose an option.
|
%010char *strptr;
*char strptr;
%010char strptr;
*strptr char;
|
1
|

Which of the following do you assign to a pointer, to initialize the pointer to a string?
|
Choose an option.
|
The contents of the pointer
The address of the pointer
The name of the string
The length of the string
|
3
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 040103t SXY Q,0,0,387,346
Using a pointer called strptr, which of the following lines of code accesses the value stored in the first element of a string called instring?
|
Choose an option.
|
%010strptr = instring;
%010strptr = *instring;
%010char strptr = instring;
%010char *strptr = instring;
|
1
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.


@@QUES 040104t SXY Q,0,0,350,335
Which of the following defines an array called cptr that contains six character pointers?
|
Choose an option.
|
%010char *cptr[5];
%010char *cptr[6];
*cptr[5];
*cptr[6];
|
2
In ANSI C which of the following are equivalent to the name of a string?
|
Choose more than one item.
|
The address of the string
The address of the first character in the string
The address of the second character in the string
The address of the null character in the string
|
1, 2
|
Which of the following initializes a pointer called stptr to a pointer called lptr?
|
Choose an option.
|
*stptr = *lptr;
*stptr = lptr;
%010stptr = *lptr;
%010stptr = lptr;
|
4
|
Which of the following lines of code are equivalent to each other if a pointer called strptr is initialized to a string called instring?
|
Choose more than one item.
|
& instring[0]
%010instring
%010strptr
*strptr
|
1, 2, 3
To which of the following is the contents of a pointer called lptr equivalent?
|
Choose an option.
|
*lptr
%010lptr
%010char *lptr
&lptr
|
1
|
Which option would you use to rewrite the header of the slength() function, shown below, as slengthp(), replacing the username array with the cptr pointer as its argument?

int slength(char username[])
|
Choose an option.
|
%010int slengthp(char cptr[])
%010int slengthp(char *cptr[])
%010int slengthp(char cptr)
%010int slengthp(char *cptr)
|
4 

Comments

Popular Posts