0% found this document useful (0 votes)
0 views5 pages

Cos201lecture Notes

The document provides an overview of the C programming language, detailing its history, standards, and basic structure. It explains the significance of C in programming, its keywords, identifiers, and variables, along with rules for naming them. Additionally, it covers the concepts of local and global variables, as well as the role of compilers and interpreters in C programming.

Uploaded by

obaloluwa085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views5 pages

Cos201lecture Notes

The document provides an overview of the C programming language, detailing its history, standards, and basic structure. It explains the significance of C in programming, its keywords, identifiers, and variables, along with rules for naming them. Additionally, it covers the concepts of local and global variables, as well as the role of compilers and interpreters in C programming.

Uploaded by

obaloluwa085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COS 201 LECTURE NOTES week 1

C PROGRAMMING LANGUAGE
An Overview of C programming Langauge.
C is a general-purpose language which has been closely associated with the UNIX operating
system for which it was developed - since the system and most of the programs that run it are
written in C. In 1972 Dennis Ritchie at Bell Labs developed C and by 1978 Brian Kernighan and
Dennis Ritchie co-wrote and published the first edition of 'the C programming language' book,
also known in the programming community as 'K&R'. For many years this text was the go-to for
C language description, definition, and reference.

In 1983, the American National Standards Institute (ANSI) established a committee to provide a
modern, comprehensive definition of C. The resulting definition, the ANSI standard, was
completed early in 1989. It was the commercial standard for the language. That version of the
language is known as “ANSI C” or C89.

C was used all around the world, so a year later in 1990 the standard was approved and adopted
by ISO, the International Standards Organization. The first version, C90, was called ISO/IEC
9899:1990.Since then, many revisions to the language have taken place.

The second version of the standard, C99, was published in 1999 called ISO/IEC 9899:1999 and
introduced new language additional features. The third version, C11, was published in 2011. The
most recent version is the forth, C17, and is called ISO/IEC 9899:2018.

Reasons why you should study C language

 Fairly easy to learn


 Structured language
 It produces fast and efficient programs.
 It can handle low-level machine functions.
 It can be compiled on a variety of computer platforms, i.e it is portable and
machine independent.
Basic Structure of C program
//the basic structure of a C program
#include <stdio.h>
int main()
{
statements;
return 0;
}
 Comments’//’ Whatever we write after the // will not affect how our code runs and the
computer will not take it into account during compilation and execution time.Those two
lines indicate that you're adding comments, which are notes to our future selves and to
our coworkers. Comments can help us remember and remind others what a certain line of
code does or why we wrote that code in the first place. It also reminds us what exactly is
the purpose of that code when we come back to it the next day of even months later.

 #include, is known as preprocessor directives. Any line starting with a # indicates to the
preprocessor that it must do something. #include <stdio.h> in the basicstructure program
above. #include literally tells the preprocessor to include, by copying and pasting, all the
code from that header file (which is an external library, stdio.h) in the place of that
statement in our own source code. Stdio.h is the standard library for input and output.
 int main ()Every C program must have one main function, The curly braces ({}) are the
body which wraps all the code that should be in our program.
This line acts starting point for all C programs. It lets the computer know where to begin
reading the code when it executes our programs.
 ‘{‘ symbol indicates the start of the program
 Statements There is at least one statement here it must appear between the opening and
closing braces. The program execution begins at the opening brace and ends at the
closing brace. The closing brace of the main function is the logical end of the program.
All statements in the within the braces end with a semicolon.
 return 0;…………the main program must return a value of integer data type
 ‘}’ symbol the signify the termination of the program

C is called a structured programming language because to solve a large problem, C programming


language divides the problem into smaller structural blocks each of which handles a particular
responsibility. These structural blocks are –

 Decision making blocks like if-else-else-if, switch-cases,


 Repetitive blocks like For-loop, While-loop, Do-while loop etc
 subroutines/procedures - functions

The program which solves the entire problem is a collection of such structural blocks. Even a
bigger structural block like a function can have smaller inner structural blocks like decisions and
loops.

Basic terms in C

Compilers
Compiler is a program that translates or converts program written in high level language
into machine language equivalent all at once. A Compiler is used to compile an entire
program and an executable program is before translating in to machine code.
Interpreter
Interpreter is a program that translates or converts program written in high level language into
machine language equivalent line-by-line. It is a program, it takes one statement of a high level
language program, translates it into machine language instruction and then immediately executes
the resulting machine language instruction and goes on.
C keywords are the words that convey a special meaning to the c compiler. The keywords cannot
be used as variable names.
The list of C keywords is given below:

auto break case char const


continue default do double else
enum extern float for goto
if int long register return
short signed sizeof static struct
switch typedef union unsigned void
volatile while

Identifiers in C

Identifiers are used as the general terminology for the names of variables, functions and arrays.
These are user defined names consisting of arbitrarily long sequence of letters and digits with
either a letter or the underscore (_) as a first character.

Rules for Naming Identifiers

The first letter of an identifier should be either alphabet or underscore.


● The alphabet can be either in uppercase or lowercase.
● The first identifier can not start with the digit.
● After the first letter identifier can have character, digit, underscore.
● Identifiers are case sensitive, uppercase and lowercase letters are distinct.
● Commas and blank space are invalid while naming an identifier.
● Maximum length of the identifier is 31 characters.
● Keywords can not be named as an identifier.
● Identifiers should be short, meaningful and easy to understand
Difference between Keyword and Identifier in C program.
 Keywords are predefined, reserved words which have a specific meaning to the
compiler. Keywords are part of syntax while writing a program and cannot be used
while naming an identifier. Identifier is a name given to entities such as variable,
function, array, structure, union , label, or any other user-defined item
 Keywords are written in lowercase while identifiers can be written in either
uppercase or lowercase.
 Meaning of keyword is predefined to the c compiler while in case of identifier the
meaning is not predefined to the c compiler.
 Keywords are combinations of alphabetical characters whereas identifiers are
collections of alphanumeric characters.
 Keywords cannot contain underscore character while identifiers can have
underscore character.
Variables in C

In C Variables are defined as A data item that may take on more than one value during the
runtime of a program.In the simplest terms, you can think of variables as a named box. A box
that acts as a storage place and location for holding different information that can vary in
content.Each box has a unique name which acts like a label put on the outside that is a unique
identifier, and the information/content lives on the inside. The content is the variable's value.

Rules for naming variables in C

 Variable names must begin either with a letter or an underscore, for example age and
_age are valid.
 A variable name can contain letters (uppercase or lowercase), numbers, or an underscore.
 There can be no other special symbols besides an underscore.
 Variable names are case sensitive, for example age is different from Age.

Local Variables
Local Variables are Variables that are declared inside a function or block are called local
variables. They can be used only by statements that are inside that function or block of
code. Local variables are not known to functions outside on their own.
Global variables
Global variables are defined outside a function, usually on top of the program. Global
variables hold their values throughout the lifetime of your program and they can be
accessed inside any of the functions defined for the program. That is, a global variable is
available for use throughout your entire program after its declaration.
-
Variable Definition in C
A variable definition tells the compiler where and how much storage to create for the
variable.
A variable definition specifies a data type and contains a list of one or more variables of
that type as follows –
type variable_list;

Here, type must be a valid C data type including char, int, float, double, bool, or any user-
defined object; and variable_list may consist of one or more identifier names separated
by
commas. Some valid declarations are shown here

int i, j, k;
char c, ch;
float f, salary;
double d;
The line int i, j, k; declares and defines the variables i, j, and k; which instruct the
compiler to create variables named i, j and k of type int.

Variables can be initialized (assigned an initial value) in their declaration. The


initializer
consists of an equal sign followed by a constant expression as follows −
type variable_name = value;
Some examples are −
int d = 3, f = 5; // definition and initializing d and f.
byte z = 22; // definition and initializes z.
char x = 'x'; // the variable x has the value 'x'.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy