Saturday, 1 December 2012

C Programming :: Structures, Unions, Enums

                                   C Programming :: Structures, Unions, Enums

1.
How will you free the allocated memory ?
A. remove(var-name); B. free(var-name);
C. delete(var-name); D. dalloc(var-name);

Answer & Explanation

Answer: Option B

2.
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

Answer & Explanation

Answer: Option B


1.
If the following structure is written to a file using fwrite(), can fread() read it back successfully?
struct emp
{
char *n;
int age;
};
struct emp e={"IndiaBIX", 15};
FILE *fp;
fwrite(&e, sizeof(e), 1, fp);

A. Yes B. No

Answer & Explanation

Answer: Option B


2.
size of union is size of the longest element in the union
A. Yes B. No

Answer & Explanation

Answer: Option A


3.
The elements of union are always accessed using & operator
A. Yes B. No

Answer & Explanation

Answer: Option B


4.
Will the following code work?
#include<stdio.h>
#include<alloc.h>

struct emp
{
int len;
char name[1];
};
int main()
{
char newname[] = "Rahul";
struct emp *p = (struct emp *) malloc(sizeof(struct emp) -1 +
strlen(newname)+1);

p->len = strlen(newname);
strcpy(p -> name, newname);
printf("%d %s\n", p->len, p->name);
return 0;
}

A. Yes B. No

Answer & Explanation

Answer: Option A


A pointer union CANNOT be created
A. Yes B. No

Answer & Explanation

Answer: Option B



MODEL BITS

                            DIPLOMA COMPUTER SCIENCE IMPORTANT BITS