Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
220 views12 pages

Unit 4 MCQ

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 12

SRM Institute of Science and Technology, Ramapuram Campus

Department of Computer Science and Engineering

18CSS101J-Programming for Problem Solving: UNIT 4 MCQ

1. How will you declare the function which is intended to receive an array as an argument
a. return_type function(type arrayname[])
b. return_type function(type arrayname[SIZE])
c. return_type function(type *arrayname)
d. All of the above

Ans: d

2. To store the array returned from the function, we can define a ______ which points to
that array.
a. Structure
b. Array
c. Pointer
d. List

Ans: c

3. The difference between Actual Parameters and Formal Parameters is that Actual


Parameters are the values that are ________ the function when it is invoked while Formal
Parameters are the variables defined by the function that _________ values when the
function is called.
a. Passed to, receives
b. Received by, pass
c. Prints, process
d. Process, prints

Ans: a

4. The advantages of using functions are:


a. Avoid repetition of codes.
b. Increases program readability.
c. Divide a complex problem into simpler ones.
d. All of the above
Ans: d
5. The C preprocessor is a __________ that is used automatically by the C compiler to
transform your program before actual compilation.
a. Macro processor
b. Microprocessor
c. Macro controller
d. Micorcontroller

Ans: a

6. Proprocessor direcives are executed ________ compilation.


a. Before
b. After
c. During
d. None of the above

Ans: a

7. The ________ preprocessor directive is used to paste code of given file into current file.
a. #define
b. #include
c. #ifdef
d. #pragma

Ans: b

8. A macro is a _________ which is replaced by the value of macro. Macro is defined


by ________ directive.
a. segment of code, #pragma
b. file, #define
c. segment of code, #define
d. none of the above

Ans: c

9. __________ is used to undefine a macro definition.


a. #udef
b. #unfed
c. #defun
d. #undef

Ans: d

10. What is the output of the following program?


#include<stdio.h>
#ifndef __MATH_H
#error First include then compile
#else
void main(){
float a;
a=sqrt(7);
printf("%f",a);
}
#endif
a. 2.64575
b. 49
c. 0.7
d. None of the above

Ans: a

11. The _____________ directive is used by the compiler to offer machine or operating-


system feature.
a. #define
b. #elif
c. #include
d. #pragma 

Ans: d

12. Calculate the output of the following program?


#include<stdio.h>
#define Area(x) x*x
#define Costpaint(x,y,z) (z*y + Area (x))
void main()
{
   int A = 8, B= 6, C = 4;
   clrscr();
   printf("The area of square= %d\n", Area(A));
   printf("Cost of paint= %d\n", Costpaint(A,B,C));
}
a. 64
b. 88
c. 32
d. 76

Ans: b

13. Identify the value that gets printed in the following program

#include <stdio.h>
int main()
{
int a=10; //variable declaration
int *p; //pointer variable declaration
p=&a; //store address of variable a in pointer p
printf("Address stored in a variable p is:%x\n",p); //accessing the address
printf("Value stored in a variable p is:%d\n",**p); //accessing the value
return 0;
}
a. 10 10
b. 10, 60ff08
c. 60ffd, 10
d. None of the above

Ans: a

14. ___________ operator can be used to evaluate size of a variable/pointer in C.


a. size()
b. eval()
c. sizeof()
d. None of the above

Ans: c

15. A pointer to void means a ________ pointer that can point to any data type.
a. Specific
b. Generic
c. Exact
d. Null

Ans: b

16. Select the possible arithmetic operations are applicable on the pointer in C language:
a. Increment, Decrement
b. Addition, Subtraction
c. Comparison
d. All of the above

Ans: d

17. What is the output of the following program:

#include<stdio.h>  
void main ()  
{  
    int arr[5] = {1, 2, 3, 4, 5};  
    int *p = arr;  
    int i;  
    printf("printing array elements...\n");  
    for(i = 0; i< 5; i++)  
    {  
        printf("%d  ",*(p+i));  
    }  
}  
a. 1, 2, 3, 4, 5
b. 5, 4, 3, 2, 1
c. 1, 2, 3, 5, 8
d. None of the above

Ans: a

18. Identify the illegal pointer arithmetic operations:


a. Address + Address
b. Address * Address
c. Address % Address
d. All of the above

Ans: d

19. What is the output of the given program:

#include<stdio.h>  
int addition ();  
int main ()  
{  
    int result;   
    int (*ptr)();  
    ptr = &addition;  
    result = (*ptr)();  
    printf("The sum is %d",result);  
}  
int addition()  
{  
    int a=5, b=2;   
    return a+b;  
}  
a. 10
b. 3
c. 7
d. 25
Ans: c
20. A ______ pointer in C cannot change the address of the variable to which it is pointing
a. Fixed
b. Null
c. Void
d. Constant
Ans: d
21. An array of pointers to strings is an array of character pointers where each pointer points
to the ________ of the string or the __________ of the string.
a. first character, base address
b. last character, last address
c. middle character, middle address
d. None of the above
Ans: a
22. A function pointer points to _____, not ____.
a. data, code
b. code, data
c. type, const
d. None of the above
Ans: b
23. Identify the correct function pointer declaration:
a. int * foo(int)
b.int (*foo)(int);
c. int (int)(*foo)
d. None of the above
Ans: b
24. What is the output of the given program:
#include <stdio.h>
void Hi_function (int times); /* function */
int main() {
void (*function_ptr)(int); /* function pointer Declaration */
function_ptr = Hi_function; /* pointer assignment */
function_ptr (3); /* function call */
return 0;}
void Hi_function (int times) {
int k;
for (k = 0; k < times; k++) printf("Hi");}
a. Hi Hi Hi Hi Hi Hi
b.Hi Hi Hi Hi Hi
c. Hi Hi Hi Hi
d.Hi Hi Hi
Ans. d
25. What is the output of the given program:
#include <stdio.h>
void* cube (const void* num);
int main() {
int x, cube_int;
x = 4;
cube_int = cube (&x);
printf("%d cubed is %d\n", x, cube_int);
return 0;}

void* cube (const void *num) {


int result;
result = (*(int *)num) * (*(int *)num) * (*(int *)num);
return result;}
a. 2 cubed is 9
b.3 cubed is 28
c. 4 cubed is 64
d.5 cubed is 26
Ans. c
26. What is the output of the given program:
#include<stdio.h>
main (){
int a[3] = {10,20,30};
int *p[3],i;
for (i=0; i<3; i++)
p[i] = &a[i]; //initializing base address of array
printf (“elements of the array are”)
for (i=0; i<3; i++)
printf ("%d \t", *p[i]); //printing array of pointers
getch();
}
a. elements of the array are 10 20 30
b.elements of the array are 9 19 29
c. elements of the array are 11 21 31
d.None of the above
Ans. a
27. What is the output of the following program:
#include<stdio.h>
main (){
int a = 10;
int *p;
int **q;
p = &a;
q = &p;
printf("%d",a);
printf("%d", *p);
printf("%d", **q);
}
a. 10 10 11
b.10 11 12
c. 10 10 10
d.None of the above
Ans. d
28. Choose the correct way of declaring pointer array:
a. datatype pointername [size];
b.datatype *pointername [size];
c. datatype[size]pointername;
d.None of the above
Ans. b
29. A ________ is a pointer that does not point to any memory location.
a. Null pointer
b.Void pointer
c. Array pointer
d.String pointer
Ans. a
30. The null pointer basically stores the ____ value.
a. Void
b.Int
c. Char
d.Null
Ans. d
31. __________ is used to initialize a pointer variable when the pointer does not point to a
valid memory address.
a. Void
b.Int
c. Char
d.Null
Ans. d
32. What is the output of the following program:
#include <stdio.h>  
int main()  
{  
    int *ptr;  
   printf("Address: %d", ptr);  
   printf("Value: %d", *ptr);  
   return 0;  
}  
a. Produces output
b. Program crashes
c. Show error
d. None of the above
Ans. b
33. What is the output of the following program:
#include <stdio.h>  
int main()  
{  
    int *ptr;  
    ptr=(int*)malloc(4*sizeof(int));  
    if(ptr==NULL)  
    {  
        printf("Memory is not allocated");  
    }  
    else  
    {  
        printf("Memory is allocated");  
    }  
    return 0;  
}  
a. Memory is not allocated
b. Memory is allocated
c. Shows compiler error
d. Program crashes
Ans. b
34. What is the output of the following program:
#include <stdio.h>  
#include <conio.h>  
#define NUMBER 0  
void main() {  
#if (NUMBER==0)  
printf("Value of Number is: %d",NUMBER);  
#endif         
getch();  
}  
a. Value of Number is: 10
b. Value of Number is: 11
c. Value of Number is: 0
d. Value of Number is 9
Ans. c
35. The #error preprocessor directive indicates error. The compiler gives fatal error
if #error directive is found and skips further compilation process.
a. #ifdef, continue
b. #error, continue
c. #ifdef, skips
d. #error, skips
Ans. d
36. What is the output of the following program:
#include <stdio.h>
int main()
{
char *cities[] = {"Iran", "Iraq"};
int i;
for(i = 0; i < 2; i++)
printf("%s\n", cities[i]);
return 0;
}
a. Iraq, Iran
b. India, Iran
c. Iran, Iraq
d. Iraq, India
Ans. c
37. What is the output of the following program:
#include <stdio.h>
#include <string.h>
void function(char**);
int main()
{
char *str = "Pointer-to-string";
int i, j = strlen(str);
for(i = 0; i < j; i++)
printf("%c", *str++);
return 0;
}
a. gnirts-ot-retnioP
b. Pointers to string
c. Pointers-to-string
d. All of the above
Ans. c
38. Choose the correct way that express the Pointer and array elements
a. a[i]
b. i[a]
c. *(a + i)
d. All of the above

Ans. d

39. What is the output of the following program:


#include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
k++;
printf("%d ",**k);
return 0;
}
a. Garbage Value
b. Compilation error
c. Runtime error
d. Linker error
Ans. c
40. What is the output of the following program:
#include<stdio.h>
int main(){
int i = 3;
int *j;
j = &i;
j++;
printf("%d ",*j);
return 0;
}
a. Garbage Value
b. Compilation error
c. Runtime error
d. Linker error
Ans.a

You might also like