C++ Multiple Choice questions and Answers PDF

71% found this document useful (55 votes)

71K views

16 pages

Description:

Multiple choice questions..

Original Title

100 TOP C Language Multiple Choice Questions and Answers _ Multiple Choice Questions and Answers Beginners and Experienced PDF

Copyright

© © All Rights Reserved

Available Formats

PDF, TXT or read online from Scribd

Share this document

Did you find this document useful?

71% found this document useful (55 votes)

71K views16 pages

100 TOP C Language Multiple Choice Questions and Answers - Multiple Choice Questions and Answers Beginners and Experienced PDF

Original Title:

100 TOP C Language Multiple Choice Questions and Answers _ Multiple Choice Questions and Answers Beginners and Experienced PDF

Jump to Page

You are on page 1of 16

You're Reading a Free Preview
Pages 6 to 14 are not shown in this preview.

Reward Your Curiosity

Everything you want to read.

Anytime. Anywhere. Any device.

No Commitment. Cancel anytime.

C++ Multiple Choice questions and Answers PDF

Latest Programming in C MCQ Objective Questions

Programming in C MCQ Question 1:

Consider the following C code given below:

void func1(char a[], char b[]) {

    int i, j;

    i = j = 0;

    while (a[i] != '\0')

        i++;

    while ((a[i++] = b[j++]) != '\0');

}

Let the string a = "1010\0100" and b = "0101011\0011". What will be the number of of characters in string a after the above function is called?

Answer (Detailed Solution Below) 11

Explanation:

  • void func1(char a[], char b[]) {
    A function func1() is called with a and b passed as string parameters.

     
  • int i, j;
    Two integer variables (i, j) will be declared and they will be used as the indices to the characters of their respective strings.

     
  • i = j = 0;
    The indices are initialised with 0 so that they can be used to point the first character of both the respective strings.

     
  • while (a[i] != '\0')  i++;
    With this line, one by one the index i will increase by 1 till the NULL character (\0) is found it will stop incrementing. Hence, after this statement executes, value of i will be 4. Any characters further will not be counted because the while condition became false and the flow is out of the while loop.
     
  • while ((a[i++] = b[j++]) != '\0');
    Now, with this statement, i = 4 and j = 0. Till b[j] encounters NULL character, b[j] will be stored in a[i] and both i and j will be incremented by 1. Hence, a becomes 10100101011. The main thing to notice here is that it will not store the NULL character of the string b in a. Hence, total 11 characters will be printed.

Programming in C MCQ Question 2:

Determine the size of the memory allocation for an object of a class.

class Exam_marks

{

   int math, eng;

   float cal_avg;

   char subject[10];

};

  1. 10
  2. 17
  3. 22
  4. 28

Answer (Detailed Solution Below)

Option 3 : 22

The correct answer is 22.

C++ Multiple Choice questions and Answers PDF
Key Points

  • line 1- class Exam_marks: Defining the class named 'Exam_marks'.

  • line 2-int math, eng; : Under the class math and eng are integer type variables.

  • line 3-float cal_avg; : The variable cal_avg is a floating type variable used for calculating the average.

  • line 4-char subject[10]; : An array variable subject[10] is defined as a character type with a size 10.

  • Now to determine the size of an object, the programmer needs to sum up all the sizes of the data members of the class, except static members.

  • Here, we will get, int= 4 bytes, float =4 bytes, char = 1 byte,

  • So, the total size will be= (2x int+1x float+ 10x char)bytes  =(2x4+ 4x1 +10x1) bytes = 22 bytes.

Thus the correct answer is 22.

C++ Multiple Choice questions and Answers PDF
Additional Information

  • The smallest size of memory is counted as bits. 8 bits is equal to 1 byte. 
  • There are different data types used for storing data in the computer system. integer type, floating type, character type etc.
  • The size of the integer data type is 4 bytes. The long data type holds 8 bytes.
  • The float is 4 bytes. The double is 8 bytes and the long double is 10 bytes.
  • The size char data type is 1 byte.

Programming in C MCQ Question 3:

After occupying the memory by calloc(), what function should be used to free the memory?

  1. dealloc()
  2. malloc(variable,0)
  3. free()
  4. demalloc(variable,0)

Answer (Detailed Solution Below)

Option 3 : free()

The correct answer is free().

C++ Multiple Choice questions and Answers PDF
Key Points

  • free(): The function free() is deallocating the memory which is occupied by the calloc() function during the program. 
  • The syntax is given below,

                               void free( void *ptr)

  • Here, ptr is defined as a pointer to a memory block that is occupied by the calloc() function during the program.
  • The free() does not return any value to the program.

Thus the correct answer is free(). 

C++ Multiple Choice questions and Answers PDF
Additional Information

  • In the C programming language, when a procedure used for changing the size of a data structure during the runtime is known as Dynamic Memory Allocation.  
  • The C programming language provides some functions to achieve these tasks.
  • Four library functions are handed by C defined under  to accelerate dynamic allocation in C programming. These are malloc(). calloc(), free(), realloc().
  • The calloc(0 functions are used for allocating contiguous memory allocation.

Programming in C MCQ Question 4:

In which order recursive functions are executed?

  1. parallel order
  2. FIFO
  3. LIFO
  4. Iterative order

Answer (Detailed Solution Below)

Option 3 : LIFO

The correct answer is LIFO.

C++ Multiple Choice questions and Answers PDF
Key Points

  • The recursive function is utilized for the capability that is alluded to as execution of itself. It is utilized for addressing any errand that is available.

  • The function of recursion has contentions that will make an errand so natural and capability won't settle on decisions further.

  • In a program, a function is made because the stack outline is known as Active Record Instance. Then, at that point, the capability call of every passage will be made.

  • Thus, it tends to be reasoned that it will be executed as LIFO which is the Last In First Out Order.

Thus the correct answer is LIFO.

C++ Multiple Choice questions and Answers PDF
Additional Information

  • A capability of a function that calls itself is known as a recursive function. Also, this strategy is known as recursion.
  • Until achieves to the goal of a program, the recursion function keeps going on.
  • The recursion functions are mainly used in data structure and algorithms. Tree traversal is a good example where the recursion function is used.

Programming in C MCQ Question 5:

What will be the output of the program?

void main()

{

  printf(“%p”, main);

}

  1. generating errors
  2. generating infinite loop
  3. print some addresses
  4. None of the above

Answer (Detailed Solution Below)

Option 3 : print some addresses

The correct answer is print some addresses.

C++ Multiple Choice questions and Answers PDF
Key Points

  • line 1: void main() - It is the main function of a program that uses some addresses.
  • line 2: printf("%p", main) - The printf function prints the output. The format specifier "%p" was used for printing the pointer data type. It will print the address of the main function.
  • The pointer holds the addresses and the format specifier "%p"  will print the address.

Thus the correct answer is print some addresses.

C++ Multiple Choice questions and Answers PDF
Additional Information

  •  The function runs a set of instructions or codes only when it is called in the program.
  •  A set of parameters, data can pass through a function.
  • A function can be called multiple times in the main function or any other function.

Top Programming in C MCQ Objective Questions

Which programming language is called the mother of programming languages?

  1. C++
  2. C
  3. Java
  4. COBOL

Answer (Detailed Solution Below)

Option 2 : C

The Correct Answer is Option (2) i.e C.

  • The C language is also known as the mother of all programming languages.
  • C is a general-purpose programming language that is used for creating a variety of applications.
  • C language was originally developed for writing operating systems. Unix Kernel and all of its supporting tools and libraries are written in C language.
  • The C language is used for the following operations :
    • Operating systems
    • Development of new languages
    • Computation platforms
    • Embedded systems
    • Graphics and Games
  • C++ and Java are the high-level languages and COBOL is a compiled English-like computer programming language.

Consider the following C declaration

struct {

short s[5];

union {

float y;

long z;

}u;

}t;

Assume that objects of type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is

  1. 22 bytes
  2. 18 bytes
  3. 14 bytes
  4. 10 bytes

Answer (Detailed Solution Below)

Option 2 : 18 bytes

The correct answer is "option 2"

CONCEPT:

Structure in C is a user-defined data type that is used to store the collection of different data types.

The total size of the structure is the sum of the size of every data member.

Union is a user-defined data type that is used to store different data types in the same memory location.

The total size of the union is the size of the largest data member.
 

EXPLANATION:

Given the size of short, float and long is 2 bytes, 4 bytes, and 8 bytes, respectively.

Therefore,

Size of Structure → size of ( short s[5] ) + size of Union  

Here, Size of Union = 8 bytes   { largest data member is long }.

Size of short s[5]  2×5  10 bytes

Size of Structure → 10+8 →18 bytes.

Hence, the correct answer is "option 2".

Consider the following C program:

#include

int main ( )

{

int a[ ] = {2, 4, 6, 8, 10};

int i, sum = 0, *b = a + 4;

for (i = 0; i < 5; i++)

sum = sum + (*b - i) - *(b - i);

printf (“ % d \ n”, sum);

return 0;

}

The output of the above C program is ________.

Answer (Detailed Solution Below) 10

integer pointer b points to 5th element of an static array a

*b = 10 // dereferencing

sum = 0 // initially

Values in loop

 sum = sum + (*b - i) - *(b - i);

i = 0

 sum = 0 + (10 - 0) - *(address_of_5th integer - 0)

 = 10 - *(address_of_5th integer)

 = 10 - 10 = 0

i = 1

 sum = 0 + (10 - 1) - *(address_of_5th integer - 1)

 = 0 + (10 - 1) - *(address_of_4th integer)

 = 9 - 8 = 1

i = 2

 sum = 1 + (10 - 2) - *(address_of_5th integer - 2)

 = 1 + (10 - 2) - *(address_of_3rd integer)

 = 9 - 6 = 3

i = 3

 sum = 3 + (10 - 3) - *(address_of_5th integer - 3)

 = 3 + (10 - 3) - *(address_of_2nd integer)

 = 10 - 4 = 6

i = 4

 sum = 6 + (10 - 4) - *(address_of_5th integer - 4)

 = 6 + (10 - 4) - *(address_of_1st integer)

 = 12 - 2 = 10

Which of the following viruses codifies itself in an automatic manner, each time it infects and copies the system.

  1. Polymorphic virus
  2. File Allocation Table (FAT) Virus
  3. Overwrite viruses
  4. Multipartite virus

Answer (Detailed Solution Below)

Option 1 : Polymorphic virus

The correct answer is ​Polymorphic virus.

C++ Multiple Choice questions and Answers PDF
Key Points

  • A polymorphic virus is a complicated computer virus that affects data types and functions.
  • Polymorphic viruses are complex file infectors that can create modified versions of themselves to avoid detection yet retain the same basic routines after every infection.
  • Upon infection, the polymorphic virus duplicates itself by creating usable, albeit slightly modified, copies of itself.
  • To vary their physical file makeup during each infection, polymorphic viruses encrypt their codes and use different encryption keys every time.
  • It is a self-encrypted virus designed to avoid detection by a scanner.

Consider the following array declaration in ‘C’ language:

int array[] = {2, 3, 4, 5};

What will be the output of the following statement?

printf("%d", 2[array]);

  1. 4
  2. 3
  3. 2
  4. 5

Answer (Detailed Solution Below)

Option 1 : 4

C++ Multiple Choice questions and Answers PDF
Key Points

 An array is defined as the collection of similar types of data items stored at contiguous memory locations. Arrays are the derived data type in C programming language which can store the primitive type of data such as int, char, double, float, etc. C array is beneficial if you have to store similar elements.

int array[] = {2, 3, 4, 5}; This array storage be like, 

C++ Multiple Choice questions and Answers PDF

The above array at index I can be accessed by, a[i], i[a], *(a+i) or *(i+a) all the above representations all are equal and gives the i th index value.

printf(%d', 2[array]); So, it gives the 2nd  index value. i.e 4.

Hence the correct answer is 4.

C++ Multiple Choice questions and Answers PDF
Additional InformationProgram: 

#include
int main()
{
    int arr[] = { 2, 3, 4, 5 };
    printf("%d ",arr[2]);
    printf("%d ",2[arr]);
    printf("%d ",*(2+arr));
    printf("%d ",*(arr+2));
    return 0;
}

Output: 4 4 4 4

So above given 2nd index value is 4 for all above print statements.

Which one of the following is not an example of computer language?

  1. ALGORITHM
  2. FORTRAN
  3. PASCAL
  4. COBOL

Answer (Detailed Solution Below)

Option 1 : ALGORITHM

The correct answer is ALGORITHM.

C++ Multiple Choice questions and Answers PDF
Key Points

  • An algorithm is a specific procedure for solving a well-defined computational problem.
  • The development and analysis of algorithms are fundamental to all aspects of Computer Science like AI, databases, graphics, networking, OS, etc.
  • Algorithm development is more than just programming.
    • It requires an understanding of the alternatives available for solving a computational problem.
    • It includes the hardware, networking, programming language, and performance constraints that accompany any particular solution.

C++ Multiple Choice questions and Answers PDF
Additional Information

  • An official language comprising a collection of instructions that produce different kinds of output is a programming language.
  • In computer science, programming languages are used to implement algorithms.
  • Most of the languages of programming consist of computer instructions.
Pascal
  • Pascal language is mostly a teaching language and few industries use this language to write the programs.
  • This language tends to use keywords instead of symbols and braces in the C language.
  • So this language is very easy for beginners to understand than a programming language like C, C++. 
Fortron
  • It is a computer programming language.
  • It was created in 1957 by John Backus.
  • The name produced from the two words FORmula TRANslation.
  • It is commonly used for numeric and scientific computing.
Cobol
  • COBOL stands for Common Business Oriented Language.
  • It is first developed in 1960 by the CODASYL Committee (Conference on Data Systems Languages).
  • It is primarily designed for use in business-oriented applications.

Considering the size of char (character) variables as one byte, what will be the size of the array declared below?

char array[ ] = “programming language”;

  1. 11 Bytes
  2. 8 Bytes
  3. 20 Bytes
  4. 21 Bytes

Answer (Detailed Solution Below)

Option 4 : 21 Bytes

Each character is of one byte:

Byte number and corresponding bytes are given for character array

1st

2nd

3rd

4th

5th

6th

7th

8th

9th

10th

11th

12th

13th

p

r

o

g

r

a

m

m

i

n

g

l

14th

15th

16th

17th

18th

19th

20th

21st

a

n

g

u

a

g

e

\0

Therefore, the size of the array declared is 21 bytes

Important Point:

\0 is null character.

What is the output in a 32 bit machine with 32 bit compiler?

#include

rer(int **ptr2,int **ptr1)

{

    int*ii;

    ii=*ptr2;

    *ptr2=*ptr1;

    *ptr1=ii;

    **ptr1 *= **ptr2;

    **ptr2 += **ptr1;

}

void main( )

{

    int var1=5, var2=10;

    int *ptr1=&var1, *ptr2=&var2;

    rer(&ptr1, &ptr2);

    printf(“%d %d “,var2, var1);

}

  1. 60   70
  2. 50   50
  3. 50   60
  4. 60   50

Answer (Detailed Solution Below)

Option 4 : 60   50

Concept –

void main()                       

Suppose var1 address 1000

var2 address 2000

int var1=5, var2=10;

var1 = 5

var2 = 10

int *ptr1=&var1, *ptr2=&var2;

ptr1 = 1000 (pointer storing address of var1)

ptr2 = 2000 (pointer storing address of var2)

rer(&ptr1,, &ptr2);

Call to the function describes in table below

rer(int **ptr2,int **ptr1)

ii

ptr2

ptr1

var1

var2

int* ii;

-

1000

2000

5

10

ii = *ptr2;

1000

1000

2000

5

10

*ptr2 = *ptr1;

2000

2000

2000

5

10

*ptr1 = ii;

2000

2000

1000

5

10

**ptr1 *= **ptr2

2000

2000

1000

5× 10 = 50

10

**ptr2 += **ptr1;

2000

2000

1000

50

60

Hence, printf(“%d %d “,var2, var1); will print 60 and 50.

Consider the following C program.

# include

struct Ournode {

        char x, y, z ;

} ;

int main ( ) {

        struct Ournode p = {‘1’, ‘0’, ‘a’ + 2} ;

        struct Ournode *q = &p;

        printf (“%c, %c”, *( (char*) q + 1) , *( (char*) q + 2) ) ;

        return 0 ;

}

The output of this program is:

  1. 0, c
  2. 0, a + 2
  3. ‘0’, ‘a + 2’
  4. ‘0’, ‘c’

Answer (Detailed Solution Below)

Option 1 : 0, c

C++ Multiple Choice questions and Answers PDF

Character ‘a’ has ASCII value 97, adding 2 will result in 99, which is the ASCII value for ‘c’.

Hence dereferencing q + 1 and q + 2 will give 0 and c respectively.

char x = 'a' + 2, that is, x == 'c'

So, p={'1','0','c'};

*((char*)q+1) = *(address of data '1' + 1) = *(address of data '0')  = 0; 

*((char*)q + 2) = *(address of data '1' + 2) = *(address of data 'c')  = c;

printf("%c, %c",*((char*)q+1),*((char*)q+2)) will print 0, c.

Consider the following C program.

#include

void mystery (int *ptra, int *ptrb) {

                int *temp;

                temp = ptrb;

                ptrb = ptra;

                ptra = temp;

}

int main () {

                int a=2016, b=0, c=4, d=42;

                mystery (&a, &b);

                if (a < c)

                mystery (&c, &a);

                mystery (&a, &d) ;

                print ("%d\n", a);

}

The output of the program is __________.

Answer (Detailed Solution Below) 2016

In the given program, in mystery function only addresses are swapped not the values. Values remain same as in the main function. Pointer swapping is local to the mystery function here.

In C language, parameters are passed by value even if they are pointer. So, there will be no change in the value of a, b, c and d.

Code Explanation:

int main () {

                int a = 2016, b = 0, c = 4, d = 42;                      // a= 2016, b= 0

                mystery (&a, &b);                                              // call void mysery (int *ptra, int *ptrb)

                if (a < c)

                mystery (&c, &a);

                mystery (&a, &d);

                printf (‘’%d\n’’, a);

}

void mysery (int *ptra, int *ptrb)                               // ptra = 2016, ptrb =0 during first call

{

                int *temp;

                temp = ptrb;

                ptrb = ptra;

                ptra = temp;                                                   // ptra = 0, ptrb = 2016,

}

But after this mystery(&a, &b); popped out of stack and all the pointers lost and all values wil remain same as original.

printf (‘’%d\n’’, a);                 // it will print the value of a i.e. 2016.

Which of the following programming languages is mainly popular for business data processing?

  1. C
  2. Pascal
  3. FORTRAN
  4. COBOL

Answer (Detailed Solution Below)

Option 4 : COBOL

The correct answer COBOL.

  • COBOL stands for Common Business Oriented Language.
  • It was developed by the US Department of Defense as a language for business data processing needs.

What is the value of the following 'C' language expression in which x is an integer variable whose value is 4?

(x - 5) ? 15: 25

  1. 0
  2. 25
  3. 15
  4. -1

Answer (Detailed Solution Below)

Option 3 : 15

C++ Multiple Choice questions and Answers PDF
Key Points

 The conditional operator is kind of similar to the if-else statement as it does follow the same algorithm as of if-else statement but the conditional operator takes less space and helps to write the if-else statements in the shortest way possible.

Syntax:

The conditional operator is of the form,

variable = Expression1? Expression2: Expression3;

It can be visualized into the if-else statement as:

if(Expression1)

{

     variable = Expression2;

}

else

{

     variable = Expression3;

}

Given that, 

(x - 5) ? 15 : 25;

here x=4, (4-5)= -1 and take it as true and print 15 as output.

If x=6, (6-5)= 1 and take it as true and print 15 as output.

If x=5, (5-5)= 0 and take it as false and print 25 as output.

Note: 

Negative values, and any non-zero values in general, are treated as true when used as conditions. For C, there are a number of contexts in which an expression is treated as a condition.

Hence the correct answer is15.

What will be the output of the following C code?

#include

main( )

{

int i;

for ( i=0; i<5; i++ )

{

             int i = 10;

             printf("%d", i);

             i++;

}

return 0;

}

  1. 10 11 12 13 14
  2. 10 10 10 10 10
  3. 0 1 2 3 4
  4. Compilation error

Answer (Detailed Solution Below)

Option 2 : 10 10 10 10 10

#include

main( )

{

int i;

for ( i=0; i<5; i++ ) //this loop runs 5 times 

{

             int i = 10;// initialized to 10

                      printf("%d", i); // It prints 10

             i++;// increamented by 1 but here i is a local variable inside a for loop.[this i values are 0,1,2,3,4] 

}

return 0;

}

Output will be 10 10 10 10 10

What is the size of the following array declaration in 'C, if character requires one-byte memory space?

char name[]="abcde";

  1. 4 bytes
  2. 6 bytes
  3. 7 bytes
  4. 5 bytes

Answer (Detailed Solution Below)

Option 2 : 6 bytes

C++ Multiple Choice questions and Answers PDF
Key Points

 char name[]="abcde"; it is a character string definition.

The string is a sequence of characters or an array of characters. The declaration and definition of the string using an array of chars is similar to declaration and definition of an array of any other data type. The constructor of the string class will set it to the C-style string, which ends at the ‘\0’.

C++ Multiple Choice questions and Answers PDF

size of above string "abcde" is =6 bytes (5 bytes + 1 byte of \0 )

Hence the correct answer is 6 bytes.

Consider the following C program.

#include

int main (  )

{

                static int a [ ] = {10, 20, 30, 40, 50} ;

                static int *p [ ] = {a, a+3, a+4, a+1, a+2} ;

                int **ptr = p;

                ptr++;

                printf(“%d%d”, ptr-p, **ptr) ;

The output of the program is _________

Answer (Detailed Solution Below) 140

Concept:

Rule of pointer arithmetic: When two pointers are subtracted belonging to same array then result is number of elements separating them.

Explanation:

Consider integer size as 2 bytes. Consider base address of array as 100.

C++ Multiple Choice questions and Answers PDF

Let array p base address is 200 and double ptr base address is 300

ptr++;                             // It points to address 202

ptr – p 

\(\frac{{address\;of\;ptr\; - \;address\;of\;p}}{{size\;of\;int}}\; = \frac{{202 - 200}}{2} = 1\;\)

** ptr = ** 202 = * (a+3) = 40

printf(“%d%d”, ptr – p, **ptr) ;

It will print 140

Consider the following C program:

#include

int main ( )

{

int arr [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 5}, *ip = arr + 4;

printf (“ % d \n”, ip[1]);

return 0;

}

The number that will be displayed on execution of the program is _________.

Answer (Detailed Solution Below) 6

int  *ip = arr + 4 //ip is a integer pointer pointing to 5 element of the array

ip[1] = *(ip + 1xsizeofint) = *(address of 6th element) = 6

Consider the following C function

#include
int main()
{

char c[] = "ICRBCSIT17";
char *p = c;
printf("%s",c + 2[p] - 6[p] - 1);
return 0;
}

The output of the program is

  1. SI
  2. IT
  3. T1
  4. 17

Answer (Detailed Solution Below)

Option 4 : 17

Here, character array c will be stored to *p.

Address 100 101 102 103 104 105 106 107 108 109 110
Element

C

R

B

C

S

T

1

7

\0
Index 0 1 2 3 4 5 6 7 8 9 10

c = 100 (starting address of array)

2[p] = p[2] = R

6[p] = p[6] = I

c + 2[p] - 6[p] - 1 

= c + R - I - 1

ASCII value of A is 65. ASCII of R is 82 and ASCII value of I is 73 

= 100 + 82 - 73 - 1 = 100 + 8 =108

Hence printf("%s", 108); will print 17 because %s will get all the values untill it gets NULL.

Match the following list:

List – I

(Storage class)

List – II

(Storage, initial – value, scope)

(a) auto

(i) register, garbage, local

(b) register

(ii) memory, zero, global

(c) static

(iii)  memory, garbage, local

(d) extern

(iv) memory, zero, local

  1. (a) – (iv), (b) – (ii), (c) – (iii), (d) – (i)
  2. (a) – (i), (b) – (iv), (c) – (ii), (d) – (iii)
  3. (a) – (ii), (b) – (iii), (c) – (i), (d) – (iv)
  4. (a) – (iii), (b) – (i), (c) – (iv), (d) – (ii)

Answer (Detailed Solution Below)

Option 4 : (a) – (iii), (b) – (i), (c) – (iv), (d) – (ii)

Concept:

Storage classes are used to fully define a variable. Storage class tells us that where the variable would be stored, what will be initial value of variable (if initial value is not specifically assigned then default value), what would be the scope of variable and life of variable.

Explanation:

Four types of storage classes: auto, register, static and extern.

auto:

Features of auto storage class are :

  • Storage is memory
  • Default value is garbage
  • Scope is local to the block in which variable is defined
  • Life till the control remains within the block in which variable is defined.


register:

Features of register storage class are:

  • Storage is in CPU registers
  • Default initial value is garbage value
  • Scope is local to the block in which variable is defined
  • Life: till the control remains within the block in which variable is defined


static:

Features of static storage class are:

  • Storage is memory
  • Default initial value is zero
  • Scope is local to the block in which variable is defined
  • Life: value of variable persists between different function calls


extern:

Features of extern storage class are:

  • Storage is memory.
  • Default initial value is zero
  • Scope is global
  • Life: as long as the program’s execution does not come to an end

If, X, Y and Z are pointer variables of type char, int and float, respectively in 'C' language, then which of the following statements is true?

  1. Size of X, Y, and Z are same
  2. Size of Z is greater than the size of X
  3. size of Y is greater than the size of X
  4. Size of Z is greater than the size of Y

Answer (Detailed Solution Below)

Option 1 : Size of X, Y, and Z are same

C++ Multiple Choice questions and Answers PDF
Key Points

 Given that,

char * x;

int * y;

float * z;

Then,

Size of x is= 2 Bytes

Size of y is= 2 Bytes

Size of z is= 2 Bytes

C++ Multiple Choice questions and Answers PDF
Important Point

  •  The size of any type of pointer in C is equal to the size of the integer variable in that system
  • The values of pointer variables are unsigned integer numbers which are addresses of other variables.
  • Thus, pointers to all types of data occupy the same size of memory because the value of a pointer is the memory address – an unsigned integer.

Hence here all pointer sizes are the same.

Hence the correct answer is Size of X, Y, and Z are the same.

What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.

int main () {

unsigned int x[4][3] =

{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};

printf(“%u, %u, %u”, x + 3, *(x + 3), *(x + 2) + 3);

}

  1. 2036, 2036, 2036
  2. 2012, 4, 2204
  3. 2036, 10, 10
  4. 2012, 4, 6

Answer (Detailed Solution Below)

Option 1 : 2036, 2036, 2036

x is a 2-D array of arrays

C++ Multiple Choice questions and Answers PDF