1/47
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is the right way to access values of structure variables: struct books { int price; int page;} book;
printf("%d%d", price.book, page.book);
printf("%d%d", book.price, book.page);
printf("%d%d", price::book, page::book);
printf("%d%d", price->book, page->book);, a.partName);
printf("%d %d", book.price, book.page);
Given the following definitions, what is the value of b[1][0]?
int b[2][2] = {{1,2}, {3, 4}};
0
1
3
this isn't a valid definition
3
What is the output of the following program:
#include
int main() {
struct Point {
int x;
int y;
float z; } p1;
p1.y=0;
p1.z=1;
p1.x=2;
printf("%d %d %.2f", p1.x, p1.y, p1.z);
return 0; }
2 0 1.00
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);
s = "wildcrazy"
What will be the output of the following?
#include
int main() {
struct p {
int k;
char c; };
int p = 10;
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p); }
10 10
Which of the following does not initialize all of the array elements to 0?
int b[2][2];
b[0][0] = b[0][1] = b[1][0] = b[1][1] = 0;
int b[2][2] = {0};
int b[2][2];
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
b[i][j] = 0;
}
}
All of the above initialize all of their elements to 0.
All of the above initialize all of their elements to 0.
Assume string1 is a character array. Which of the following operations does NOT produce a string?
string1[] = "test";
string1[] = {'t', 'e', 's', 't'};
string1[] = {'t', 'e', 's', 't', '\0'};
string1[] = " ";
string1[] = {'t', 'e', 's', 't'};
What will be the output of the following?
#include
int main() {
struct {
int k;
char c;
};
struct p;
p.k = 10;
printf("%d\n", p.k);
}
10
Correct the following code of the errors so that the program runs without errors?
#include
int main () {
struct employee {
int id;
char name[20];
} emp;
employee.id = 8;
printf(%d , id);
return 0;
}
#include
int main () {
struct employee {
int id;
char name[20];
} emp; // The structure variable `emp` is declared here.
emp.id = 8; // Correctly reference the `id` member of the structure variable `emp`.
printf("%d\n", emp.id); // Correctly format the `printf` statement and reference `emp.id`.
return 0;
}
Which of the following is not a correct way to initialize an array?
int n[5] = {7};
int n[5] = {6, 6, 6};
int n[5] = {0, 7, 0, 3, 8, 2};
int n[] = {0, 7, 0, 3, 8, 2};
int n[5] = {0, 7, 0, 3, 8, 2};
Constant variables ______
-can be assigned values in executable statements
-can be used to specify array sizes, but this makes programs harder to
-understand
-can be used to specify array sizes, thereby making programs more scalable --do not have to be initialized
can be used to specify array sizes, thereby making programs more scalable.
What will be the values of k[1] and k[3] after execution of the code segment below using the data shown?
When you input the following data: 2 0 1
int k[6] = {0, 0, 0, 0, 0, 0};
int i, n;
for (i = 3; i < 6; ++i) {
scanf("%d", &n);
k[n] = i;
}
k[1] is 5
k[3] is 0
k[1] is 5
k[3] is 2
k[1] is 5
k[3] is 1
k[1] is 5
k[3] is 3
k[1] is 5k[3] is 0
_______ may contain different data types.
structures
arrays
arrays and structures
Neither arrays nor structures
structures
In C, it is appropriate to say that a string is a(n) __________.
pointer
integer
double quote
sequence of characters contained in single quotes
sequence of characters contained in single quotes
What will be the output of the program? #include
compilation error
What is the output of the following program fragment?
int a=4;
void write()
{
int a=10;
printf("a = %d", a);
}
int main(){
int a = 5;
write();
printf("a = %d", a);
return 0;
}
a = 10 a = 5
What is the output of the following code fragment?
int x;
char z = 'a';
if (x = z) printf("One");
else printf("Two");
One
Point out the error in the following program error or warning.
#include
int main()
{
display();
return 0;
}
void display()
{
printf("IndiaBIX.com");
}
display() is called before it is defined
____________ process occurs when the programmer finds and corrects the code that is causing the error(s).
debugging
What type of operators are the following? > < >= <= == !=
relational operators
What is the output of the following code fragment?
int x = 10;
int y = 7;
if(2 x > 3 y)
printf("Hello");
else
printf("Bye");
Bye
Which operator would make the following expression True?
False _______ True
OR
Text enclosed in / / in a C program _________.
causes syntax error
gives instructions to the processor
is ignored in the C compiler
makes files available
is ignored in the C compiler
For what exact range of values of variable x does the following code segment display the letter 'C'?
if (x <= 200)
if (x < 100)
if (x <= 0)
printf("A\n");
else
printf("B\n");
else
printf("C\n");
else
printf("D\n");
-----------------------------
x > 200
100 < x <= 200
0 < x < 100
100 <= x <= 200
———————————————
100 < x <= 200
What will be the output of the program?
#include
int main()
{
int a=100, b=200, c;
c = (a == 100 || b > 200);
printf("c=%d\n", c);
return 0;
}
---------------------------------
c= 100
c= 200
c= 300
c =1
c=1
Which of the following is NOT a data type of a variable?
number
float
character
integer
number
If num is a variable of type int and temp is a variable of type double, how could you correctly complete this function call?
scanf("%f%d", _________);
-------------------
temp,num
&temp,&num
&num,&temp
num,temp
&temp, &num
The function ___________ comprises one or more statements that are executed when the function is called.
header
body
data
type
definition
body
Given the following C Code, rewrite the program code to correct these errors.
1: / What's wrong with this program? /
2: #include stdio.h
3: int main();
4: }
5: int a, b, c \ Three integers /
5: a = 3
6: b = 4
7: c = a + b
8: printf("The value of c is %d" + C);
9: return 0;
10: }
Line 1: / What's wrong with this program? /#include
int a, b, c; / Three integers /
Line 8: printf("The value of c is %d" , c)
What will be the output of this program fragment?
int value = 0;
do {
printf ("%d", value%2);
value = value +1;
} while (value <5);
01010
How many times will the following loop iterate?
int j = 1;
while (j>5) {
printf("%d", j);
}
No iterations
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
What is the output of the following program fragment?
double x[8] = {16.0, 12.0, 6.0, 8.0, 2.5, 12.0, 14.0, -54.5};
int j = 5;
printf("%.2f\t", x[j] + 1) ;
printf("%.2f", x[j + 1]);
13.00 14.00
What will be the output of this program fragment?
int i =0;
while (i<3) {
printf ("%d%d", i, 5-i);
i=i+1;
}
051423
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 will be the output of the program?
#include
1, 40, 0
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.
What is the subscript index for the data value 92 in the example given below?
int score [5] = {83, 92, 78, 94, 71}
One
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 ("%d%d", i, 5-i);
i=i+1;
}
05 15 23
Which loop is specifically designed to initialize, test, and increment a counter variable?
for loop
When the elements in an array are stored from lowest to highest, the array is sorted in __________ order.
Ascending
What will be the output of this program fragment? int i; for(i = 0 ; i=1 ; ++i){ printf("ans1"); printf("ans2");
}
infinite loop
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
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
What is the output of the following code fragment?
int i;
for(i = 0 ; i<2 ; i++){
printf("ans1");
printf("ans2");}
ans1ans2ans1ans2
How many times is the loop body of the while statement executed?
int g = 0;
int s = 0;
int t = 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
Suppose a program contains the code
for (i = 1; i < 10; i++) {
n[i] = 1;
}
It is initializing successive elements of an array.