- What is printed by the following program.
#include <stdio.h>
int main()
{
int i, sum=0;
int vector[]={8, 6, 2, 4, 1, 8, 4, 0, 2, 1};
int *x, *y, *z;
x=vector;
y=&vector[4];
z=&vector[7];
for (i=0;i<3; i++)
sum += *(x+i) + *(y+i) + *(z+i);
printf("%d %d\n", sum, y-x);
return 0;
}
OUTPUT
32 4
2. The function prototype
double mySqrt( int x );
(a) defines a function called mySqrt which takes an integer as an argument and returns a double
(b) defines a function called double which calculates square roots
(c) defines a function called mySqrt which takes an argument of type x and returns a double
(d) defines a function called mySqrt which takes a double as an argument and returns an integer
ANS:(a)
3. If a = 7.0, b = 7.0 and c = 6.0, then what is printed by
printf( “%.2f”, sqrt( a + b * c ) );
a) 49
b) 7.00
c) 7
d) 49.00
ANS: (b)
4. Using the following function definition, the parameter list is represented by
A B( C ) {
D
}
(a) A
(b) B
(c) C
(d) D
ANS: (c)
5. Using the following function definition, the return value type is represented by
A B( C ) {
D
}
(a) A
(b) B
(c) C
(d) D
ANS: (a)
6. Which of the following functions does not contain any errors?
(a) void printnum ( int x )
{
print( “%i”, x );
return x;
}
(b) int cube( int s )
{
int s;
return ( s * s * s );
}
(c) double triple ( float n )
{
return ( 3 * n );
}
(d) double circumference ( int r );
return ( 5.14 * 2 * r );
ANS: (c)
7. int square( int ); is an example of a function __________.
a) datatype
b) stereotype
c) prototype
d) proceduretype
ANS: (c)
8. As used in
int square( int );
int is not a(n) __________.
a) data type
b) parameter type
c) return type
d) function prototype
ANS: (d)
9. The most concise notation to use to define function parameters x and y as double is __________.
a) x, y
b) x, double y
c) double x, y
d) double x, double y
ANS: (d)