Basic of C notes

 Basic of C notes

Basics of “C”

 

Objectives

Understand the basic structure of a program in C.

Learn the commands used in UNIX/LINUX and MS-DOS for compiling and running a program in C.

Obtain a preliminary idea of the keywords in C.

Learn the data types, variables, constants, operators, and expressions in C.

Understand and grasp the precedence and associativity rules of operators in C.

Get acquainted with the rules of type conversions in C.

 

Key Words

ASCII : It is a standard code for representing characters as numbers that is used on most microcomputers, computer terminals, and printers. In addition to printable characters, the ASCII code includes control characters to indicate carriage return, backspace, etc.

 

Assembler :The assembler creates the object code.

 

Associativity :The associativity of operators determines the order in which operators of equal precedence are evaluated when they occur in the same expression. Most operators have a left-to-right associativity, but some have right-to-left associativity.

 

Compiler: A system software that translates the source code to assembly code.

Constant :A constant is an entity that doesn’t change.

 

Data type: The type, or data type, of a variable determines a set of values that the variable might take and a set of operations that can be applied to those values.

 

Debugger: A debugger is a program that enables you to run another program step-by-step and examine the value of that program’s variables.

 

Identifier: An identifier is a symbolic name used in a program and defined by the programmer. Ex : name of variables, arrays, functions etc like emp_name, total_amount

 

IDE :An Integrated Development Environment or IDE is an editor which offers a complete environment for writing, developing, modifying, deploying, testing, and debugging the programs.

 

Identifier: An identifier or name is a sequence of characters invented by the programmer to identify or name a specific object.

 

Keyword: Keywords are explicitly reserved words that have a strict meaning as individual tokens to the compiler. They cannot be redefined or used in other contexts.

 

Linker: If a source file references library functions or functions defined in other source files, the linker combines these functions to create an executable file.

 

Precedence :The precedence of operators determines the order in which different operators are evaluated when they occur in the same expression. Operators of higher precedence are applied before operators of lower precedence.

 

Pre processor :The C pre processor is used to modify the source program before compilation according to the pre processor directives specified.

 

L-value: An l-value is an expression to which a value can be assigned.

 

R-value :An r-value can be defined as an expression that can be assigned to an l-value.

 

Token: A token is one or more symbols understood by the compiler that help it interpret your code.

 

Word :A word is the natural unit of memory for a given computer design. The word size is the computer’s preferred size for moving units of information around; technically it’s the width of the processor’s registers.

 

Whitespace Space, newline, tab character and comment are collectively known as whitespace.

 

Variable: A variable is a named memory location. Every variable has a type, which defines the possible values that the variable can take, and an identifier, which is the name by which the variable is referred.

 

Bug:Any type of error in a program is known as bug. There are three types of errors that may occur:

üCompile errors,

üLinking errors,

üRuntime errors

 

Why Learn “C” ?

 

There are a large number of programming languages in the world today even so, there are several reasons to learn C, some of which are stated as follows:

a . C is quick.

b . C is a core language : In computing, C is a general purpose, cross-platform, block structured procedural, imperative computer programming language.

c . C is a small language: C has only thirty-two keywords. This makes it relatively easy to learn compared to bulkier languages.

d . C is portable

 

Developing Programs in “C”

There are mainly three steps:

1.Writing the C program

2.Compiling the program and

3.Executing it.

§For these steps, some software components are required, namely an operating system, a text editor(integrated development environment), the C compiler, assembler, and linker.§C uses a semicolon as a statement terminator; the semicolon is required as a signal to the compiler to indicate that a statement is complete.

§All program instructions, which are also called statements, have to be written in lower case characters.

 

 

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Backlash Code

 

Parts of C Program

Header File

The header files, usually incorporate data types, function declarations and macros, resolves this issue. The file with .h extension is called header file, because it’s usually included at the head of a program.

Every C compiler that conforms to the international standard (ISO/ IEC 9899) for the language will have a set of standard header files supplied with it.

The header files primarily contain declarations relating to standard library functions and macros that are available with C.

 

Standard Header Files

During compilation, the compilers perform type checking to ensure that the calls to the library and other user-defined functions are correct. This form of checking helps to ensure the semantic correctness of the program.

 

 

Philosophy : main()

main() is a user defined function. main() is the first function in the program which gets called when the program executes. The start up code c calls main() function. We can’t change the name of the main() function.

§ main() is must.

According to ANSI/ISO/IEC 9899:1990 International Standard for C, the function called at program start up is named main. The implementation declares no prototype for this function. It can be defined with no parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv) :

int main(int argc, char *argv[ ]) { /* ... */ }

 

 

 

Structure : C Program

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Declaration & Definition

Declaration means describing the type of a data object to the compiler but not allocating any space for it.

 

A declaration announces the properties of a data object or a function. If a variable or function is declared and then later make reference to it with data objects that do not match the types in the declaration, the compiler will complain.

ü data_type variable_name_1,

 

Definition means declaration of a data object and also allocating space to hold the data object.

 

üA definition, on the other hand, actually sets aside storage space (in the case of a data object) or indicates the sequence of statements to be carried out (in the case of a function).

 

Variables : Attributes

All variables have three important attributes:

 

üA data type that is established when the variable is defined, e.g., integer, real, character. Once defined , the type of a C variable cannot be changed.

A name of the variable.

A value that can be changed by assigning a new value to the

variable. The kind of values a variable can assume depends on its type. For example, an integer variable can only take integer values, e.g., 2, 100, –12.


DOWNLOAD THIS NOTE HERE : LINK FOR PDF

Next topic will be on Data Types

 

 

 

 

Previous
Next Post »