CSC 211 Lecture-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Nigerian Army University, Biu.

Faculty of:

Computing
Department of

Computer Science

Course:
Computer Programming I (CSC-211)
Course Lecturer: Mr. AM Gimba

CSC 211-NAUB 1
Introduction to C Programming Language
A programming language is a formal language, which comprises a
set of instructions/commands that produce various kinds of output.
Programming languages are used in computer programming to
implement algorithms.

The programming language C was developed in the 1970s by


Dennis Ritchie at Bell Labs (Murray Hill, New Jersey) in the process
of implementing the Unix operating system.

CSC 211-NAUB 2
C is a powerful and compact computer programming language that
allows you to write programs that specify exactly what you want
your computer to do. You’re in charge: you create a program,
which is just a set of instructions, and your computer will follow
them. Programming in C isn’t difficult, as you’re about to find out.
I’m going to teach you all the fundamentals of C programming in
an enjoyable and easy-to-understand way, and by the end of this
semester you’ll have written your first few C programs. It’s as easy
as that!
CSC 211-NAUB 3
Common Mistakes

Mistakes are a fact of life. When you write a computer program in


C, the compiler must convert your source code to machine code,
and so there must be some very strict rules governing how you use
the language. Leave out a comma where one is expected, or add a
semicolon where you shouldn’t, and the compiler won’t be able to
translate your program into machine code.

CSC 211-NAUB 4
Compiler

The compiler is an application software that converts your source


code into machine language and detects and reports errors in the
compilation process. The input to this stage is the file you produce
during your editing, which is usually referred to as a source file.

The compiler can detect a wide range of errors that are due to
invalid or unrecognized program code, as well as structural errors.

CSC 211-NAUB 5
#include<stdio.h>

the header file provides standard input/output functions.

void main ()

this shows the start of the function, main body of the program

this opening brace indicates the start of the body of the main() function

The body of the function contains executable statements, each of which must be terminated
with a semicolon

this closing brace indicates the end of the body of the main() function.

CSC 211-NAUB 6
Keywords
Keywords are predefined, reserved words in C language and each of
which is associated with specific features. These words help us to use
the functionality of C language. They have special meaning to the
compilers.
There are total 32 keywords in C.
auto double int struct

break else long switch

case enum register typedef

char extern return union

continue for signed void

do if static while

default goto sizeof volatile

const float short unsigned


CSC 211-NAUB 7
Variable

A variable is a specific portion or space of memory in your


computer that consists of one or more attached bytes. Every
variable has a name, and you can use that name to refer to that
place in memory to retrieve what it contains or store a new data
value there. A variable is a name given to memory location, that is
used to hold value, which may get modified during program
execution.

CSC 211-NAUB 8
Naming variables the name that you give to a variable,
conveniently referred to as a variable name, can be defined with
some flexibility. A variable name is a sequence of one or more
uppercase or lowercase letters, digits, and underscore characters
(_) that begins with a letter (incidentally, the underscore character
counts as a letter). Examples of legal variable names are as
follows:

CSC 211-NAUB 9
Examples of legal variable names are as follows:
firstname
gender
Monthly_Salary
Date_of_birth
_naub
Height
lenght
room1
room2

CSC 211-NAUB 10
Constants

If you want to define a variable whose value cannot be changed,


you can use the const keywords. This will create a constant. For
example

const double PI = 3.14;

const int tax = 200;

Const float bonus = 2.467;

CSC 211-NAUB 11
Literals
A literal is a value (or an identifier) whose value cannot be altered
in a program. For example: 1, 2.5, 'c' etc.
String Literals
A string literal is a sequence of characters enclosed in double-quote
marks. For example:
“good” //string constant
“” //null string constant
“ ” //string constant of white space
“x” //string constant having a single character
“Welcome to NAUB” //prints string with newline

CSC 211-NAUB 12
Identifier

An identifier is a string of alphanumeric characters that begins


with an aphabetic character or an undersocore character that are
used for various programming elements such as variables,
functions, arrays, structures, unions and so on. Actually, an
identifier is a user-defined word.

An identifier can only have alphanumeric characters (a-z, A-Z, 0-9)


and underscore (_).
CSC 211-NAUB 13
Rules for naming identifiers
 An identifier consists of a sequence of letters (A to Z, a to z),
digits (0 to 9), and underscores (_). For example, Count, _number,
names, faculty_of_computing, _name. But, my name,
computer science are invalid identifiers/name.
The first character of an identifier must not be a digit.
For example, 2information, 7NAUB, are inlavid identifiers.

CSC 211-NAUB 14
Identifiers are case-sensitive. For example name, Age is the
same as Age always, but age is not the same as Age, also
NUMBER is the same as NUMBER, But Number is not the same as
NUMBER.

The lenght of an identifier should be less than 32 characters.


Although there is no limit to the lenght of an identifier, some
compilers support names/identifiers of up to the first 32
characters only.
CSC 211-NAUB 15
It must not be a keyword of C language

CSC 211-NAUB 16
END

CSC 211-NAUB 17

You might also like