C Programming > Functions

C Programming Questions and Answers

C Programming > Functions

Postby abdulsaboor » Sun Oct 05, 2014 9:58 am

C Programming > Functions

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

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
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987
Cell=0334-7165488
Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2000
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Functions

Postby abdulsaboor » Sun Oct 05, 2014 1:12 pm

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
2. ANSI Notation
B. 1. Pre ANSI C Notation
2. KR Notation
C. 1. ANSI Notation
2. KR Notation
D. 1. ANSI Notation
2. Pre ANSI Notation

Answer: Option C

Explanation:

KR Notation means Kernighan and Ritche Notation.
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987
Cell=0334-7165488
Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2000
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Functions

Postby abdulsaboor » Sun Oct 05, 2014 1:13 pm

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 overflows

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.
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987
Cell=0334-7165488
Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2000
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan


Return to C Programming

Who is online

Users browsing this forum: No registered users and 1 guest
cron