Loading...

C Multiple Choice Questions

Our C questions and answers focuses on all areas of C programming language covering 100+ topics in C

C Structures-3 MCQs

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



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



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



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;



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



6. Which of the following uses structure?

a) Array of structures
b) Linked Lists
c) Binary Tree
d) All of the mentioned



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



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



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



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



- Related Topics