Documente Academic
Documente Profesional
Documente Cultură
http://www.cquestions.com/2012/02/data-type-questions-in-c.html
http://www.indiabix.com/c-programming/pointers/
Directions
Step 1 : Identify solution without any assistance (compiler, text book, Google, etc).
Step 2 : Research (text book, Google), work (compiler), and implement the solution.
Resolve the difference by collaborating and corroborating with your class mates. If still not resolved, check with me.
Due to compilers using different standards and some not conforming to standards, it is possible for the output to be different or
incorrect. So it’s important that you identify the correct version and use that as reference for the exam preparation.
If the code generates a compilation error, then identify the reason for the error and fix it.
Questions Lesson(s) Learned
1 What is the similarity between a structure, union and
enumeration?
A. All of them let you define new values
B. All of them let you define new data types
C. All of them let you define new pointers
D. All of them let you define new structures
2 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main()
{
union var
{
int a;
int b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
}
3 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI,
SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE,
WED, THU, FRI, SAT);
}
A. -1, 0, 1, 2, 3, 4
B. -1, 2, 6, 3, 4, 5
C. -1, 0, 6, 2, 3, 4
D. -1, 0, 6, 7, 8, 9
4 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
struct employee
{
char name[20];
int age;
};
void modify_byVal(struct employee v)
{
v.age=v.age+2;
}
void main()
{
struct employee Sam = {"Sam", 35};
struct employee Mary = {"Mary", 25};
modify_byVal(Sam);
modify_byRef(&Mary);
void main()
{
struct emp
{
char gender;
int age;
char name[20];
};
struct emp e1 = {‘M’,"David", 23};
struct emp e2 = {‘M’,"David", 23};
if(e1 == e2)
printf("The structures are equal");
else
printf("The structures are not equal");
}
A. “The structures are equal”
B. “The structures are not equal” is printed
because garbage values fill up the
remaining space in variable name
C. Compile error: Structure cannot be compared
using '=='
D. No output
D. None of above
void main()
{
struct emp
{
char name[25];
int age;
float bs;
};
struct emp e;
e.name = "Steven";
e.age = 25;
printf("%s %d\n", e.name, e.age);
}
8 What is the outcome of this code when compiled
and executed?
#include<stdio.h>
void main()
{
struct emp
{
char *name;
int age;
float bs;
};
struct emp e;
e.name = "Steven";
e.age = 25;
printf("%s %d\n", e.name, e.age);
}
9 Which of the following statements correctly assigns 12
to structure member month?
#include<stdio.h>
struct date
{
int day;
int month;
int year;
};
void main()
{
struct date d, *pdt;
pdt = &d;
}
I. pdt.month = 12
II. &pdt.month = 12
III. d.month = 12
IV. pdt->month = 12
A I & III
B. III & IV
C. I & III
D. II & IV
10 A union cannot be nested in a structure
A. True
B. False
11 Nested unions are allowed
A. True
B. False
12 One of the elements of a structure can be a pointer to
the same structure.
A. True
B. False
13 One of the elements of a structure can be a variable of
the same structure.
A. True
B. False
14 A structure can be nested inside another different
structure.
A. True
B. False
15 The '.' operator can be used to access structure
elements using a structure variable.
A. True
B. False
16 Union elements can be of different sizes.
A. True
B. False
17 Union elements must be different sizes.
A. True
B. False
18 The '->' operator can be used to access structures
elements using a pointer to a structure variable only
A. True
B. False
19 It is not possible to create an array of pointer to
structures.
A. True
B. False
20 Structures can be compared by using operators ==
and !=
Why?
21 Given
struct card {
char *face;
char *suit;
} c, *cPtr;
cPtr= &c;
*cPtr->face
cPtr.face
cPtr->face
card->face
22 Given
union values {
char w;
float x;
double y;
};
int main()
{
int i, n, a = 4;
scanf("%d", &n);
for (i = 0; i < n; i++)
a = a * 2;
}
• A. Logical Shift left
• B. No output
• C. Arithmetic Shift right
• D. bitwise exclusive OR
33
What is the outcome of this code when compiled and
executed?
#include<stdio.h>
void main()
{
int a=4;
int b=8;
int c= a | b;
printf("%d\n",c);
}
34
What is the outcome of this code when compiled and
executed?
#include<stdio.h>
void main()
{
int a=4;
int b=8;
if ( a & b)
printf("True");
else
printf("False");
}