You are on page 1of 11

Sources / sites

http://www.cquestions.com/2012/02/data-type-questions-in-c.html

http://www.indiabix.com/c-programming/pointers/

Directions

Step 1 : Identify solution without any assistance (compiler, text book, Google, etc).

Step 2 : Research (text book, Google), work (compiler), and implement the solution.

Step 3: Compare your expected result and actual result.

Resolve the difference by collaborating and corroborating with your class mates. If still not resolved, check with me.

Due to compilers using different standards and some not conforming to standards, it is possible for the output to be different or
incorrect. So it’s important that you identify the correct version and use that as reference for the exam preparation.

Some questions might refer to topics we have not covered yet for the current exam. Save it for the future exam.

If the code generates a compilation error, then identify the reason for the error and fix it.

Questions Lesson(s) Learned


1 The keyword used to transfer control from a function back to the Return
calling function is https://www.indiabix.com/c-
A. switch programming/functions/
B. goto
C. go back
D. return
2 What is the outcome/output of the following C program, if any? 9
#include<stdio.h> --I means subtract one from I before print

void main(void)
{
int fun(int);
int i = fun(10);
printf("%d\n", --i);
}
int fun(int i)
{
return (i++);
}
3 What is the outcome/output of the following C program, if any? 3314
#include<stdio.h>
int i; Answer
int fun1(int); 4343
int fun2(int); Explanation
Program wants to do fun1 first
void main(void) and then fun2
{ Program calls to fun1 executes
int i=3; then continue first but pulls
fun1(i); variable assignment out first.
printf("%d,", i); Void main only uses the
fun2(i); variable inside void main
printf("%d", i); regardless if incremented
} outside.
int fun1(int j)
{
printf("%d,", ++j);
return 0;
}
int fun2(int i)
{
printf("%d,", ++i);
return 0;
}
4 int addmult(int ii, int jj) Return(kk, ll);
{ “,” discards first variable,
int kk, ll; keeps second
kk = ii + jj;
ll = ii * jj; Answer 12 12
return (kk, ll);
}

void main(void)
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d, %d\n", k, l);
}
5 A function cannot be defined inside another function TRUE
A. True Function can be called in
B. False another function

6 Functions cannot return values of more than one variable at a time true
A. True
B. False
7 If return type for a function is not specified, it defaults to int t
A. True
B. False
8 Functions can be called either by value or reference t
A. True
B. False
9 A function may have any number of return statements, each returning it’s T
independent values. https://www.indiabix.com/c-
A. True programming/functions/029002
B. False #6
10 Every function must return a value No #2
A. Yes https://www.indiabix.com/c-
B. No programming/functions/030001
11 Functions cannot return a floating point number Yes #2
A. Yes https://www.indiabix.com/c-
B. No programming/functions/030001

12 Will the following functions work? No, the reason is i think


int f1(int a, int b) because there is no main{}????
{ correct me if im wrong ,
return ( f2(20) ); IN A WHOLE STRING I
} AGREE WITH YOU ALEX
int f2(int a) BUT ITS JUST A PORTION
{ OF CODE
return (a*a); assuming this code is just a
} portion of code, i want to say it
will work only based on i know
you can call functions inside of
functions
https://www.indiabix.com/c-
programming/functions/030001
this website has explanition
DOES WORK
13 Is it true that too many recursive calls may result into stack overflow? Y
A. Yes https://www.indiabix.com/c-
B. No programming/functions/030002
#7 on website

14 In a function two return statements should never occur. N


A. Yes https://www.indiabix.com/c-
B. No programming/functions/030002
#8
15 What’s wrong with the function below A-GUESS
int f(int a, int b) C-IS CORRECT
{
https://www.indiabix.com/c-
int a;
a = 20; programming/functions/027001
return a;
#1
}
A.Missing parenthesis in return statement
B.The function should be defined as int f(int a)
C.Redeclaration of a
D. All the above
E.None of above
16 void main(void) D
{
Cant find online but with out
int x=10, y=5;
    funcB(y,x); declaring what type of funciton
}
“funcB(y,x)” is you will get an
int funcB(int x, int y) error
{
printf(“x is %d y is %d\n”,x,y);
}
a) x is 10 y is 5
b) x is 5 y is 10
c) Logic error
d) Compile error

17 int add(int x);


 5
void main(void)
{  goes back to
int x=5, y =5; similar problem
add(x); line of thinking
printf("x is %d\n",x); local variable
}
takes
int add(int x) precedence
{ over global
x = x + 10;
return x; If string of code
} “

A. x is 15 x=add(x);” was
B. x is 5 added before
C. Compile error : variable y not used “printf(“x is
None of the above %d\n”,x);” this
assigns the
function output
to the local
operator X
18 What is the expected behavior of the following code?
#include<stdio.h> 5 10 
int swap(int x, int y);
Dont have to declare
int main(void) LOCAL VARIABLE HAS
{
int x=5, y =10; PRECEDENCE OVER GLOBAL
swap(x,y);
printf("X is %d Y is %d\n",x,y);
}

int swap(int x, int y)


{
int temp=x; // preserve x value in temp
x = y; // replace x value with y
y = temp; // recall the original x value stored in temp
}

A. Compile error : X and Y not declared


B. X is 10 Y is 5
C. X is 5 Y is 10
Y is 10 X is 5

19 What is the output of this program 1+2=3+3=6+4=10+5=15+6=21+7=2


#include <stdio.h> 8+8=36
#include <stdlib.h> funcA runs 8 times
incrementing each time as sequence
int funcA(int i) shown above
{ once it completes if statement
int tmp=0; reaching 0 at the 8th i-1 it outputs
if (i>0) that last number to int x at bottom
{ and prints x
tmp=(i + funcA(i-1)); giving us the double 36 at the end
printf("%d",tmp); actual output:
return tmp; 136101521283636
} Clarity output:
else 1,3,6,10,15,21,28,36,36
return 0;
}
int main(void)
{
int x = funcA(8);
printf("%d",x);
}

What is the output of this program Static int


https://www.codesdope.com/discussi
int givemesum() on/what-is-the-difference-between-
{
static-int-and-int/
  static int num = 10;
  return num--;
}
It returns 10 and 9
 
int main(void) Static makes the
{
 
   printf("%d ", givemesum ());
   printf("%d ", givemesum ());
  return 0;
}

You might also like