<< Chapter < Page Chapter >> Page >

C expressions are arranged in the following groups based on the operators they contain and how you use them:

  • Arithmetic expression
  • Conditional expression
  • Assignment expression
  • Comma expression
  • lvalue
  • Constant expression

Expressions are used as

  • Right hands of assignment statements
  • Actual parameters of functions
  • Conditions of if statements
  • Indexes of while statements
  • Operands of other expressions . . . .

Functions

A subprogram (also known as a procedure or subroutine) is nothing more than a collection of instructions forming a program unit written independently of the main program yet associated with it through a transfer/return process. Control is passed to the subprogram at the time its services are required, and then control is returned to the main program after the subprogram has finished.

The syntax used to represent the request of subprogram varies among the different language. The techniques used to describe a subprogram also varies from language to language. Many systems allow such program units to be written in languages other than that of the main program.

In most procedural programming languages, a subprogram is implemented as though it were completely separate entity with its own data and algorithm so that an item of data in either the main program or the subprogram is not automatically accessible from within the other. With this arrangement, any transfer of data between the two program parts must be specified by the programmer. This is usually done by listing the items called parameters to be transferred in the same syntactic structure used to request the subprogram’s execution.

The names used for the parameters within the subprogram can be thought of as merely standing in for the actual data values that are supplied when the subprogram is requested. As a result, you often hear them called formal parameters, whereas the data values supplied from the main program are refereed to actual parameters.

C only accept one kind of subprogram, function. A function is a sub program in which input values are transferred through a parameter list. However, information is returned from a function to the main program in the form of the “value of the function”. That is the value returned by a function is associated with the name of the function in a manner similar to the association between a value and a variable name. The difference is that the value associated with a function name is computed (according to the function’s definition) each time it is required, whereas when a variable ‘s value is required, it is merely retrieve from memory.

C also provide a rich collection of built-in functions.There are more than twenty functions declared in<math.h>. Here are some of the more frequently used.

Name Description Math Symbols Example
sqrt(x) square root x sqrt(16.0) is 4.0
pow(x,y) compute a value taken to an exponent, xy x y pow(2,3) is 8
exp(x) exponential function, computes ex e y exp(1.0) is 2.718282
log(x) natural logarithm ln x log(2.718282) is 1.0
log10(x) base-10 logarithm log x log10(100) is 2
sin(x) sine sin x sin(0.0) is 0.0
cos(x) cosine cos x cos(0.0) is 1.0
tan(x) tangent tg x tan(0.0) is 0.0
ceil(x) smallest integer not less than parameter x size 12{ lceil x rceil } {} ceil(2.5) is 3; ceil(-2.5) is –2
floor(x) largest integer not greater than parameter x size 12{ left lfloor x right rfloor } {} floor(2.5) is 2; floor(-2.5) is –3

Library

The library is not part of the C language proper, but an environment that support C will provide the function declarations and type and macro definitions of this library.The functions, types and macro of the library are declared in headers.

C header files have extensions .h. Header files should not contain any source code. They are used purely to store function prototypes, common #define constants, and any other information you wish to export from the C file that the header file belongs to.

A header can be accessed by

#include<header>

Here are some headers of Turbo C library

stdio.h Provides functions for performing input and output.

stdlib.h Defines several general operation functions and macros.

conio.h Declares several useful library functions for performing "console input and output" from a program.

math.h Defines several mathematic functions.

string.h Provides many functions useful for manipulating strings (character arrays).

io.h Defines the file handle and low-level input and output functions

graphics.h Includes graphics functions

Statements

A statement specifies one or more action to be perform during the execution of a program.

C requires a semicolon at the end of every statement.

Comments

Comments are marked by symbol “/*” and “*/”. C also use // to mark the start of a comment and the end of a line to indicate the end of a comment.

1. The Hello program written using the first commenting style of C /* A simple program to demonstrateC style comments The following line is essentialin the C version of the hello HUT program */#include<stdio.h>main() {printf /* just print */ ("Hello HUT\n"); }The Hello program written using the second commenting style of C // A simple program to demonstrate// C style comments //// The following line is essential // in the C version of the hello HUT program#include<stdio.h>main() {printf("Hello HUT\n"); //print the string and then go to a new line }
Got questions? Get instant answers now!

By the first way, a program may have a multi-line comments and comments in the middle of a line of code.However, you shouldn’t mix the two style in the same program.

C program structure

A C program basically has the following form:

  • Preprocessor Commands : Declare standard libraries used inside the program
  • Type definitions : Define new data types used inside the program
  • Function prototypes : Declare function types and variables passed to function.
  • Variables : State the names and data types of global variables
  • Functions: Include the main function(required) and the functions that their prototypes were announced above.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to computer science. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10776/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to computer science' conversation and receive update notifications?

Ask