0% found this document useful (0 votes)
62 views8 pages

A - B. C. D .: Answer: Option C Explanation

The document provides explanations for 7 multiple choice questions related to C programming. It covers topics such as: 1) Using the fmod function to obtain the remainder after dividing two floating point numbers. 2) The different types of linkages in C including external, internal, and none. 3) Valid variable name symbols in C, which include letters, digits, and underscores. 4) The difference between extern declarations and normal function declarations. 5) How to round a value up to the next whole number using ceil. In each question, multiple choice options are provided for the answer along with a short explanation of the correct option. This allows the document to concisely quiz and
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
62 views8 pages

A - B. C. D .: Answer: Option C Explanation

The document provides explanations for 7 multiple choice questions related to C programming. It covers topics such as: 1) Using the fmod function to obtain the remainder after dividing two floating point numbers. 2) The different types of linkages in C including external, internal, and none. 3) Valid variable name symbols in C, which include letters, digits, and underscores. 4) The difference between extern declarations and normal function declarations. 5) How to round a value up to the next whole number using ceil. In each question, multiple choice options are provided for the answer along with a short explanation of the correct option. This allows the document to concisely quiz and
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

1. Which of the following statements should be used to obtain a remainder after dividing 3.

14 by
2.1 ?
A
rem = 3.14 % 2.1;
.
B.rem = modf(3.14, 2.1);
C.rem = fmod(3.14, 2.1);
D
Remainder cannot be obtain in floating point division.
.
C

Answer & Explanation


Answer: Option C
Explanation:
fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point
divisions.
Example:

#include <stdio.h>
#include <math.h>

int main ()
{
printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) );
return 0;
}
Output:
fmod of 3.14/2.1 is 1.040000

2. What are the types of linkages?


A
Internal and External B.External, Internal and None
.
C.External and None D.Internal
B

Answer & Explanation


Answer: Option B
Explanation:
External Linkage-> means global, non-static variables and functions.
Internal Linkage-> means static variables and functions with file scope.
None Linkage-> means Local variables.

3. Which of the following special symbol allowed in a variable?


A
* (asterisk) B.| (pipeline)
.
C.- (hyphen) D._ (underscore)
D

Answer & Explanation


Answer: Option D
Explanation:
Variable names in C are made up of letters (upper and lower case) and digits. The underscore
character ("_") is also permitted. Names must not begin with a digit.
Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=>foo_bar
=> _foo42
=> _
=>QuUx

4. Is there any difference between following declarations?

1 : extern int fun();


2 : int fun();
A
Both are identical
.
B.No difference, except extern int fun(); is probably in another file
C.int fun(); is overrided with extern int fun();
D
None of these
.
B

Answer & Explanation


Answer: Option B
Explanation:
externint fun(); declaration in C is to indicate the existence of a global function and it is
defined externally to the current module or in another file.
int fun(); declaration in C is to indicate the existence of a function inside the current module or
in the same file.

5. How would you round off a value from 1.66 to 2.0?


A
ceil(1.66) B.floor(1.66)
.
C.roundup(1.66) D.roundto(1.66)
A

Answer & Explanation


Answer: Option A
Explanation:
/* Example for ceil() and floor() functions: */

#include<stdio.h>
#include<math.h>

int main()
{
printf("\n Result : %f" , ceil(1.66) );

printf("\n Result : %f" , floor(1.66) );

return 0;
}

// Output: Result : 2.000000


// Output: Result : 1.000000

6. By default a real number is treated as a


A
float B.double
.
C.long double D.far double
B

Answer & Explanation


Answer: Option B
Explanation:
In computing, 'real number' often refers to non-complex floating-point numbers. It include
both rational numbers, such as 42 and 3/4, and irrational numbers such as pi = 3.14159265...
When the accuracy of the floating point number is insufficient, we can use the double to
define the number. The double is same as float but with longer precision and takes double
space (8 bytes) than float.
To extend the precision further we can use long double which occupies 10 bytes of memory
space.

7. Which of the following is not user defined data type?


struct book
{
char name[10];
1: float price;
int pages;
};
2: long int l = 2.35;
3: enum day {Sun, Mon, Tue, Wed};
A
1 B.2
.
C.3 D.Both 1 and 2
B

Answer & Explanation


Answer: Option B
Explanation:
C data types classification are
1. Primary data types
1. int
2. char
3. float
4. double
5. void
2. Secondary data types (or) User-defined data type
1. Array
2. Pointer
3. Structure
4. Union
5. Enum
So, clearly long int l = 2.35; is not User-defined data type.
(i.e.longint l = 2.35; is the answer.)
8. Is the following statement a declaration or definition?
extern int i;
A
Declaration B.Definition
.
C.Function D.Error
A

Answer & Explanation


Answer: Option A
Explanation:
Declaring is the way a programmer tells the compiler to expect a particular type, be it a
variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie.
extern int i)
Declaration never reserves any space for the variable or instance in the program's memory; it
simply a "hint" to the compiler that a use of the variable or instance is expected in the
program. This hinting is technically called "forward reference".

9. Identify which of the following are declarations

1 : extern int x;
2 : float square ( float x ) { ... }
3 : double pow(double, double);
A
1 B.2
.
C.1 and 3 D.3
C

Answer & Explanation


Answer: Option C
Explanation:
externint x; - is an external variable declaration.

doublepow(double, double); - is a function prototype declaration.

Therefore, 1 and 3 are declarations. 2 is definition.

10. In the following program where is the variable a getting defined and where it is getting
declared?
#include<stdio.h>
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a=20;
A.extern int a is declaration, int a = 20 is the definition
B.int a = 20 is declaration, extern int a is the definition
C.int a = 20 is definition, a is not defined
D.a is declared, a is not defined
A

Answer & Explanation


Answer: Option A
Explanation:
- During declaration we tell the datatype of the Variable.
- During definition the value is initialized.

11. When we mention the prototype of a function?


A.Defining B.Declaring
C.Prototyping D.Calling
B

Answer & Explanation


Answer: Option B
Explanation:
A function prototype in C or C++ is a declaration of a function that omits the function body
but does specify the function's name, argument types and return type.
While a function definition specifies what a function does, a function prototype can be
thought of as specifying its interface

1. The keyword used to transfer control from a function back to the calling function is
A
switch B.goto
.
C.go back D.return
D

Answer & Explanation


Answer: Option D
Explanation:
The keyword return is used to transfer control from a function back to the calling function.
Example:
#include<stdio.h>
int add(int, int); /* Function prototype */

int main()
{
int a = 4, b = 3, c;
c = add(a, b);
printf("c = %d\n", c);
return 0;
}
int add(int a, int b)
{
/* returns the value and control back to main() function */
return (a+b);
}
Output:
c=7

2. What is the notation for following functions?


1. int f(int a, float b)
{
/* Some code */
}

2. int f(a, b)
int a; float b;
{
/* Some code */
}
A 1. KR Notation 1. Pre ANSI C Notation
B.
. 2. ANSI Notation 2. KR Notation
1. ANSI Notation 1. ANSI Notation
C. D.
2. KR Notation 2. Pre ANSI Notation
C

Answer & Explanation


Answer: Option C
Explanation:
KR Notation means Kernighan and Ritche Notation.

3. How many times the program will print "IndiaBIX" ?


#include<stdio.h>

int main()
{
printf("IndiaBIX");
main();
return 0;
}
A
Infinite times B.32767 times
.
C.65535 times D.Till stack doesn't overflow
D

Answer & Explanation


Answer: Option D
Explanation:
A call stack or function stack is used for several related purposes, but the main reason for
having one is to keep track of the point to which each active subroutine should return control
when it finishes executing.
A stack overflow occurs when too much memory is used on the call stack.
Here function main() is called repeatedly and its return address is stored in the stack. After
stack memory is full. It shows stack overflow error.

You might also like