E-learning

Computer-Based Training (CBT) or Internet-Based Training (IBT) or Web-Based Training (WBT) courses at BengalStudents website

Question and Answer

Q What is the main difference between a function declaration and a function definition?

A The main difference between a function declaration and a function definition is that the former does not reserve any memory space, nor does it specify what a function does. A function declaration only alludes to a function definition that is placed elsewhere. It also specifies what type of arguments and values are passed to and returned from the function. A function definition, on the other hand, reserves the memory space and specifies tasks the function can complete.

Prototyping Functions

Prototyping Functions

In the following subsections, we’re going to study three cases regarding arguments passed to functions. The first case is a function that takes no argument; the second one is a function that takes a fixed number of arguments; the third case is a function that takes a variable number of arguments.
Functions with No Arguments

The first case is a function that takes no argument. For instance, the C library function getchar() does not need any arguments. It can be used in a program like this:

Declaring Functions

Declaring Functions

As you know, you have to declare or define a variable before you can use it. This is also true for functions. In C, you have to declare or define a function before you can call it.

Declaration Versus Definition

Exercises : Answer the following Question

To help solidify your understanding of this lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson. The answers and hints to the questions and exercises are given in Appendix E, “Answers to Quiz Questions and Exercises.”
Quiz

Given the following code portion, which variables are global variables, and which ones are local variables with block scope?

Question and Answer

Question and Answer

Q Can a global variable be hidden by a local variable with block scope?

A Yes. If a local variable shares the same name with a global variable, the global

variable can be hidden by the local variable for the scope of the block within which the local variable is defined with block scope. However, outside the block, the local variable cannot be seen, but the global variable becomes visible again.

Q Why do you need the static specifier?

The Storage Class Specifiers

The Storage Class Specifiers

In C, the storage class of a variable refers to the combination of its spatial and temporal regions.

You’ve learned about scope, which specifies the spatial region of a variable. Now, let’s focus on duration, which indicates the temporal region of a variable.

There are four specifiers and two modifiers that can be used to indicate the duration of a variable. These specifiers and modifiers are introduced in the following sections.
The auto Specifier