1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
How many times is the loop body of the while statement executed?
int g = 0;
int s = 0;
int z = 0;
int i = 0;
while (i <=5){
scanf("%d", &t);
s = s+ t;
if (t >= 0);
g = g + 1;
else
z = z + 1;
i = i + 1;
}
6 times
How many times will the following loop iterate?
int j = 1;
while (j>5){
printf("%d", j);
}
No iterations
Which loop is specifically designed to initialize, test, and increment a counter variable?
for loop
Which of the following statement is true about the statement below?
int score [5] = {83, 92, 78, 94, 71};
This is an array declaration and initialization.
Suppose a program contains the code
for (i = 1; i < = 10; i++){
n[i] = 1;
}
It is initializing successive elements in an array.
What is the subscript index for the data value 92 in the example given below?
int score [5] = {83, 92, 78, 94, 71}
one
What will be the output of this program fragment?
char u, v, temp; u = 'a'; v = 'b'
while (v != 'a'){
temp = u;
u = v;
v = temp;
}
printf("%c %c", u, v);
ba
What is the output of the following program?
#include
void bing(int n){
printf("%4d", n);
}
int main(void){
double x;
x = 41;
bing(x);
printf("%.2f\n", x);
return (0);
}
41 41.10
What will be the output of this program fragment?
int value = 0;
do{
printf("%d", value);
value = value + 2;
}
while (value <5);
024
How many of the parameters are considered input parameters in the function below?
voidapart(double x, int wholep, double fracp){
*wholep = (int)x;
fracp = x - wholep;
}
1
Which of the following is optional when writing a function definition?
return statement
Which of the following code segments does not contain any errors?
double triple(float n){
return (3 * n);
}
What will be the output of this program fragment?
int value = 1;
do{
printf("%d\n", value);
value = value + 2;
}
while (value <5);
1
3
The function prototype
double mySqrt(int x);
defines a function called mySqrt which takes an integer as an argument and returns a double.
What is the output of the following program fragment?
double x[8] = {16.0, 12.0, 6.0, 8.0, 2.5, 12.0, 12.0, -54.5};
int j = 5;
printf("%.2f\t", x[j] + 1);
printf("%.2f\t", x[j + 1]);
13.00 14.00
Given below prototype of a function:
void five(double x, double yp, int zp);
Given these variable declarations:
int m, n;
double p, q;
What could be a valid call to function five()?
five(6.2, &p, &n);
When the elements in an array are stored from lowest to highest, the array is sorted in __________ order.
ascending
int square(int); is an example of a function ________.
prototype
What will be the output of this program fragment?
int i;
for(i = 0; i = 1; ++i){
printf("ans1");
printf("ans2");
infinite loop
Which of the following is NOT a correct way to initialize an array?
int n[5] = {0, 7, 0, 3, 8, 2);
What is the output of the following code fragment?
int i;
for(i = 0; i<2; i++){
printf("ans1");
printf("ans2");
ans1ans2ans1ans2
A valid reason for building programs out of functions is:
All of the above
How many times will the following loop iterate?
int k = 1;
while (k<=5){
printf("%d", k);
}
Infinite
What will be the output of this program fragment?
int i = 0;
while (i<3){
printf("\t%d %d", i, 5-i);
i = i+ 1;
}
05 14 23
What is the output of the following code fragment?
int x = 0;
while (x<=3){
printf("%d\t", x + 2);
x++;
}
2 3 4 5
In the fragment below, what is the minimum size of result required for successful and valid concatenation of "double" and "trouble"?
strcpy(result, "double");
strcpy(result, "trouble");
15
What is the value of the expression that follows?
strcmp("dog", "Dog");
1
What is the value of variable "s" after execution of the program fragment below?
char h[6] = "wild";
char p[6] = "crazy";
char s[10];
strcpy(s, h);
strcat(s, p);
"wildcrazy"
_______ may contain different data types.
structures
What does the following function do?
int func(int m, int n){
int ans;
if (n == 0)
ans = m;
else
ans = 1 + func(m, n-1);
return (ans);
}
performs two integer addition
What is the value of the expression that follows?
strcmp("dog", "Dog");
1
Keyword _________ introduces the structure definition.
struct
Which function does NOT read data from standard input?
printf
To test whether a character is one of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, use the _________ standard library function.
isdigit
What does the following function do?
int func(int n){
int ans;
if (n == 1)
ans = 1;
else
ans = n + func(n-1);
return (ans);
Computes (addition of numbers .. (n-1) + n) using a recursive definition.
What will be the output of the following?
#include
void main(){
struct student{
int no;
char name[20];
};
struct student s;
no = 8;
printf("%d", no);
}
Compile time error
What is the right way to access values of structure variable book{price, page}?
printf{"%d %d", book.price, book.page);
What value is return by the following call to strlen?
strlen("robot")
5
Consider the following code fragment: char str[10];
scanf("%s", str);
What will happen if scanf encounters the string "programming" when scanning a value for str?
Function scanf will store the entire string "programming", even though there is insufficient space in str. The string will overflow str.
What will be the output of the following?
#include
struct p {
int k;
char c;
};
int p = 10;
int main(){
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}
10 10
Given the following structure definition:
struct part{
unsigned int partNumber;
char partName[25];
};
Reading the a part number and the a part name from the keyboard into the individual members of a structurepart variable called a.
scanf("%d %24s", &a.partNumber, a.partName);
In C, it is appropriate to say that a string is a(n) ________.
pointer
What will be the output of the following?
#include
struct{
int k;
char c;
};
int main(){
struct p;
p.k = 10;
printf("%d\n", p.k);
}
Compile time error
What does the deck[52] array contain in the following statement?
struct card a, deck[52], *cPtr;
card structure elements
What is the value of the expression that follows?
strcmp("5", "49");
1
What is the output of the following program:
#include
struct Point{
int x, y, z;
};
int main(){
struct Point p1 = {.y = 0, .z = 1, .x = 2};
printf("%d %d %d", p1.x, p1.y, p1.z);
return 0;
}
2 0 1
Consider the following code fragment.
char str[10];
scanf("%s", str);
What will happen if scanf encounters the string "vivaciously" when scanning a value for str?
Function scanf will store the entire string "vivaciously", even though there is insufficient space in str. The string will overflow str.
If the printf function is passed a character array that is not null terminated it will:
print the contents of the character array and keep printing characters in memory until it encounters a null character
Which function returns the length of a string, not including the null terminator?
strlen
What does the following function do?
int c_digits(const char *str){
int ans;
if (str[0] =='\0')
ans = 0;
else
if (isdigit(str[0]))
ans = 1 + count_digits(&str[1]);
else
ans = count_digits(&str[1]);
return (ans);
}
Counts the number of digits in the string str