C Structures-3
1. What is actually passed if you pass a structure variable to a function?
a) Copy of structure variable
b) Reference of structure variable
c) Starting address of structure variable
d) Ending address of structure variable
Answer: A
Yes, If you pass a structure variable by value without & operator, only a copy of the variable is passed. So changes made within that function do not reflect in the original variable.
2. Can the following C code be compiled successfully?
#include <stdio.h>
struct p {
int k;
char c;
float f;
}
int main() {
struct p x = {.c = 97,.f = 3,.k = 1};
printf("%f\n", x.f);
}
a) Yes
b) No
c) Depends on the standard
d) Depends on the platform
Answer: C
No explanation is given for this question.
3. Which of the following operation is illegal in structures?
a) Typecasting of structure
b) Pointer to a variable of the same structure
c) Dynamic allocation of memory for structure
d) All of the mentioned
Answer: A
No explaination is given for this question.
4. The correct syntax to access the member of the ith structure in the array of structures is?
struct temp {
int b;
}s[50];
a) s.b.[i];
b) s.[i].b;
c) s.b[i];
d) s[i].b;
Answer: D
No explanation is given for this question.
5. Comment on the output of hte following C code.
#include <stdio.h>
struct temp {
int a;
int b;
int c;
};
main() {
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
a) No Compile time error, generates an array of structure of size 3
b) No Compile time error, generates an array of structure of size 9
c) Compile time error, illegal declaration of a multidimensional array
d) Compile time error, illegal assignment to members of structure
Answer: A
No explaination is given for that question.
6. Which of the following uses structure?
a) Array of structures
b) Linked Lists
c) Binary Tree
d) All of the mentioned
Answer: D
No explaination is given for this question.
7. What is the output of given program if user enter "xyz"?
#include <stdio.h>
void main() {
float age, ageInSeconds;
int value;
printf("Enter your age : ");
value = scanf("%f", &age);
if(value == 0) {
printf("\nYour age is not valid");
}
ageInSeconds = 365*24*60*60*age;
printf("\nYou have lived for %f seconds", ageInSeconds);
}
a) Enter your age : xyz Your age is not valid
b) Enter your age: xyz You have lived for 0 seconds
c) Enter your age: xyz Your age is not valid
d) Complier error
Answer: C
When we give scanf() a %f format string, that means "We want you to try and get us a floating point number. When we provide input like xyz, it's not going to match anything, because xyz is not a valid floating-point number.
8. What will be the output of the following piece of code?
for(i = 0; i < 10; i++);
printf("%d", i);
a) 10
b) 0123456789
c) Syntax error
d) 0
e) Infinite Loop
Answer: A
Due to semicolon(;) at the end of the for loop, after 10 iterations for loop will be terminated and the result will be 10.
9. The type of the controlling expression of a switch statement cannot be of the type ________
a) int
b) char
c) short
d) float
e) long
Answer: D
No explaination is given for this question.
10. What's wrong in the following statement, provided k is a variable of type int?
for(k = 2, k <= 12, k++)
a) The increment should always be ++k
b) The variable must always be the letter i when using a for loop
c) There should be a semicolon at the end of the statement
d) The variable k can’t be initialized
e) The commas should be semicolons
Answer: E
In for loop the three statements parts are separated by two semicolons which are missing here.