Chapt 6 – Thinking in C: Programming with functions

A function must be either declared or defined before it’s use. To declare a function we need to specify the function prototype like this:

float avg(int, int);

A void is used to signify no parameters. If a function sayHello() takes no parameters, it can be defined like this:
void sayHello(void) {}
or like this
void sayHello() {}
In this case we may pass parameters to the function, but they will be ignored by the compiler as well as the runtime.

This section goes beyond functions and also mentions different variable types:

  • local variables are those that are declared in methods. They exist on the stack.
  • constant variables declared at the file level, reside in the data segment, and cannot be accessed from other files
  • variables declared at the file level also reside on the data segment, but can be accessed from other files

Research:

  • What is the data segment?
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: