Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

High Level Language

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

INTRODUCTION

C is a general-purpose language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972. C is usually a compiled programming language. The computer cannot understand the language directly, so a program called a compiler converts the C into the machine code instructions which do the job. Actually getting a program to run is however a two stage process It combines the features of high-level language and low- level language. It is well suited for writing both application software and system software. High level language: It is easily understandable by the humans. It cannot be understand directly by the computer, it requires complier or interpreter to convert the programming code into machine language. Low level language:
Low level languages are very close to machine so it is very faster; it is very difficult to understand by humans. It can be converted to machine code without using a compiler or interpreter.

Some good examples of low-level languages are assembly and machine level language.

Features of C: Low level language support Structured Programming Efficient use of pointers Program portability Compactness Reusability Acceptability

Low level language support


C programming provides low level features that are generally provided by the lower level languages. C is closely related to lower level language such as assembly language.

Structured Programming:
Well suited for writing system software and application software It allows programmer to divide a big program into small programs.

Efficient use of pointers:


It is the only way to express some computations. It produces compact and efficient code. It provides a very powerful tool.

Portability:
C programs are portable so it can be run on any complier with or without any modification. C language setup size is around 3 5 MB. C is a portable language. Portable means that a C program written for one computer system can be run on another system with little or no modification

COMPACTNESS:
C is a language of few words, containing only a handful terms, called keywords, which serve as the base on which the languages functionality is built.

REUSABILITY:
C is modular, C code can and should be written in routine called functions. These functions can be reused in other applications or programs. By passing pieces of information to the function, you can create useful, reusable code.

Advantages:
C is compiler based language rather than interpreter based. So, c language program can be compiled in speed. C is portable language. C is the collection of lot of library files. C language support good graphics. C language support system programming. C language support number of operators. C language support strong handling.

Disadvantages:
There is no run time checking in c language. It does not support exception handling. It has no strict type checking.

Applications:
It is used for creating computer applications. It is used in writing Embedded Software. It is used to implement different Operating system operations. It is also used in developing verification software, test code, simulators etc.

SRTUCTURE OF A C PROGRAM:
Structure of C program is defined by set of rules called protocol, to be followed by programmer while writing C program. All C programs are having sections/parts which are mentioned below. 1. 2. 3. 4. 5. Documentation section Preprocessor Directives Global declaration section Function Main User defined function definition section

Documentation Section The Documentation Section consists of a set of comment in the non-executable statement. The comment includes name of the program, headings, created date, author, etc. Comment can be in two ways: Single Line Comment: Comment can be given in single line. It is indicated by //. Example: //Find the largest number Multiple line comment: Comment can be given in multiple line. It is indicated by /* and */. Example: /* Write a C++ program to find the sum and average of five numbers. */.

Preprocessor Directives: It link files from Compiler library to program code. It begins with # symbol otherwise syntax error will be occurred. Two types of common preprocessor directives are #include and #define. Preprocessor program executes automatically and process the program code. These statements instruct the compiler to include C preprocessors such as header files and symbolic constants before compiling the C program. Preprocessing occurred before a program is compiled. Example:#include<stdio.h>.

Directive #define #include #undef #ifdef #ifndef #if #else #elif #endif #error #pragma

Description Substitutes a preprocessor macro Inserts a particular header from another file Undefines a preprocessor macro Returns true if this macro is defined Returns true if this macro is not defined Tests if a compile time condition is true The alternative for #if #else an #if in one statement Ends preprocessor conditional Prints error message on stderr Issues special commands to the compiler, using a standardized method

Global declaration section: The variable used throughout the program is called global variable. The variables are declared before the main ( ) function as well as user defined functions are called global variables The global variable are declared and used by the main function or sub function. The global variables can be accessed by all the user defined functions including main ( ) function.

Example: int a=2; int I; double fact; Function Main: Every program written in the c language contain main( ) function. Empty parenthesis after main is necessary. The main function is always the first code executed when a program starts. The program execution starts from the opening brace { and ends with the closing braces }. This section contains Declaration part: Declaration Part declares all the variables used in the executable part. Initialization of variables are also done I this section. Initialization means providing initial value to the variables.

Executable part: This part contains the set of a statement or a single statement following the declaration of a variable. These statements are enclosed between the braces.

User defined function definition section: It is defined by the user at the time of writing program. These functions are made for code reusability and for saving time and space.

main( ) { ======= ======= function01( ); ======= } function01( ); {

======== ======== }

Comments:
Comments are given by the programmer to understand the program easily. It is kind of statements placed between the delimiters /* & */ so the compiler does not execute comments. Comments are not a part of executable programs. Comments can be used through multiple lines.

Uses of C structures: 1. 2. 3. 4. 5. 6. C Structures can be used to store huge data. Structures act as a database. C Structures can be used to send data to the printer. C Structures can interact with keyboard and mouse to store the data. C Structures can be used in drawing and floppy formatting. C Structures can be used to clear output screen contents. C Structures can be used to check computers memory size etc.

int main() { int num; printf("Enter an integer you want to check: "); scanf("%d",&num); if((num%2)==0) /* Checking whether remainder is 0 or not. */ printf("%d is even.",num); else printf("%d is odd.",num);

return 0; }

#include <stdio.h> #include <string.h> struct student { int id; char name[20]; float percentage; }; int main() { struct student record = {0}; //Initializing to null record.id=1; strcpy(record.name, "Raju"); record.percentage = 86.5; printf(" Id is: %d \n", record.id); printf(" Name is: %s \n", record.name); printf(" Percentage is: %f \n", record.percentage); return 0;

Output:
Id is: 1 Name is: Raju Percentage is: 86.500000

EXECUTING THE PROGRAM:


The steps essential in executing a c program are: Creating Compiling Linking Executing.

Creating: c program can be created using text editors such as Notepad, WordPad, and Borland c/c++. The created file is saved using .C EXTENSION. Example: addition.c. The file saved using .C EXTENSION is called source file. The default extension is C. The user can also specify his/her own extension.

FUNDAMENTALS OF C: The basic elements used to construct a simple C program they are given below. C character set, Identifiers and keywords, Data types, Constants, Arrays, Declarations, Expressions and statements.

C Character Set: C uses letters A to Z in lowercase and uppercases, the digits 0 to 9, certain special characters, and white spaces to form basic program elements (e.g. variables, constants, expressions etc.) Alphabets:

A, B, C, D, ,X, Y, Z a, b, c, d, ,x, y, z Digits : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Special Symbols : ~!@#%^&*()_-+=|\{} []:;"'<>,.?/ The white spaces used in C programs are: blank space, horizontal tab, carriage return, new line and form feed. Identifiers: Identifier is a name that identifies objects and classes. It given to variables, constants, functions and user - define data. It has some set of rules.

In identifier the first character can only in alphabets even upper and lower case or underscore (_) because it also consider as a letter.

Keywords are not allowed to be identifiers. No special characters are considered as identifiers. For example comma, semicolon, slash and etc..,

Keywords: Keywords are reserved words in programming language. It is already predefined meaning in c. all the keywords are have fixed meaning it cant be changed by the user. In c programming 32 keywords are there.

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

Data types: In C, variable or data should be declared before it can be used in program. C language has some predefine set of data types. Size of variable, constant and array are determined by data types. Each data types having different types of storage capabilities. It supports two different types of data types. Primary data types. Derived data types. Primary data types: The primary data types having four fundamentals data types, they are given below Integer - int. Floating float. Character char. Void.

Integer: Keyword int is used to define integer numbers. It occupies 2byte(16 bit complier) or 4byte(32 bit complier) memory. It allows storing numeric values. We cant store decimal values in int data type. If you want to use the integer that crosses the limit we need to go for long int. EX: Int count; Count=5; Floating float: Float is use to define the floating point numbers. It is used to store real numbers with single precision. It occupies 4 bytes of memory. The type modifier for float is long. It has the same memory requirements as double. For example: 10.456789 can be stored in a variable using float data type. Double: It is used to store real numbers with double precision. It occupies 8 bytes of memory. The type modifier for double is long. A long double occupies 10 bytes of memory. For example: The range for double data type is from 1E37 to 1E+37. Character char: Character types are used to store the character value. It stores any value from the C character set. The type modifiers for characters are signed and unsigned. Both the signed and unsigned characters are occupies 1 byte of memory. Characters like a letters that means alphabets from A-Z. The data type has modifiers. The modifiers are divided into four types, these are given below Short Long Signed Unsigned

Void: It is used to specify an empty set containing no values. Hence, it occupies 0 bytes of memory. This is usually used to specify the functions and pointers. Derived data type:

Constants: Constants are the terms that cant be changed during the program execution. It refers fixed values. A constant is a number or character string that can be used as a value in program. Use constants to represent floating-point, integer, enumeration, or character values that cannot be modified. C supports several types of constants that I am discussing in this article. These fixed values are also called literals.

CONSTANTS

PRIMARY CONSTANTS

SECONDARY CONSTANTS

INTEGR

REAL

CHAR

ARRAY

POINTER

STRC

ENUM

MM

The constants are divided in to 2 types they are given below

Primary constants Secondary constants

Primary constants: The primary constants are classified as 3 types they are given below Integer constants Real constants Character constants

Integer constants: An integer literal or constants can be a decimal, octal, or hexadecimal constant. These constants are the numeric constants it associated with numbers without any fractional or exponential part. There are three types of integer constants are there

Decimal Integer: Decimal integer constants are consisting of 0 to 9 and positive or negative sign. Octal Integer: Octal integer constants are consisting of 0 to 7. Hexadecimal Integer: The hexadecimal integer constants are consisting of 0 to 9 in numeric and also letters from A to F. Real constants: The real constants are also called floating point constants. The real constants are the numeric constants it associated with fractional numbers. For example (-0.1, 0.00234) Character constants: The character constants are enclosed in the single quotes with single alphabet, single number or single special character. For example a ,d ,V.., Secondary constants: Array Pointer Structure Enum

Array: C programming language provides a data structure called the array; it is used to store a collection of data, the data having same types. In c program the main problem is to handle the similar types of data. For example:

If the user wants to store marks of 100 students. This can be done by creating 100 variables individually. This type of problem can be handled in C programming using arrays. It has two types One dimensional arrays Multidimensional arrays Pointer: Pointer is a user defined data type which creates special types of variables. which allocate the address in memory of another variable. An address is the actual address-of a variable in the computer memory. It is the only way to express some computations. It produces compact and efficient code. It provides a very powerful tool. For example the pointer is define as int *ptr; Structure: Structure is a user defined data type. It is a collection of variables under a single name. It contains unlimited numbers of NAMED sub categories (or fields). For example: a student record may contain the students, name, age, gpa, etc. Each category of information is defined by its name and type (e.g., name is a string, age is an integer).

Enum: The enum keyword is used to declare an enumeration. It is a primitive data type, which is user defined. An enum is a distinct type consisting of a set of named constants. Enumeration improves code clarity and makes program easier to maintain. Enumeration in C also provides more security by better error-checking technology and compiler warnings. For example enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

enum months : byte { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }; Variables:

A variable is nothing but a name given to a storage area that our programs can manipulate. It is high-level programming languages, in C, it is just a named area of storage that can hold a single value Each variable in C has a specific type, which determines the size and layout of the variable's memory; The name of a variable can be composed of letters, digits, and the underscore character. The Programming language C has two main variable types Local Variables

Global Variables Operators:

Operators are the symbol which operates on value or variables. Operators form expressions by joining individual constants, The symbols which are used to perform
logical and mathematical operations in a C program are called C operators.

For example:

Here the values or numbers are called as a operands. The symbols are called operators.
7 * 5 = 35 and 2 + 8 = 10

C includes a large number of operators which fall into different categories. Arithmetic operators Assignment operators Relational operators Logical operators Bit wise operators Conditional operators (ternary operators) Increment/decrement operators Special operators Arithmetic operators:

The arithmetic operators are defining as they are used to perform the mathematical operations like addition, subtraction, multiplication, division and module.

Two types of arithmetic operators are there, they are Binary operators Unary operators

Binary operator:

operator

Meaning Of Operator
addition or unary plus

Examples
6 + 5 = 11

subtraction or unary minus

5-2=3

multiplication

4*2=8

division remainder after division( modulo division)

8/2=4

10 % 3

Unary operators:

Operator + var - var ++ -Size of

Meaning of operator Unary plus Unary Minus Increment Decrement Gives the size of operator

You might also like