0% found this document useful (0 votes)
16 views6 pages

C Prorgamming

Uploaded by

Alemat Tesfay
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)
16 views6 pages

C Prorgamming

Uploaded by

Alemat Tesfay
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/ 6

C Programming

Coding is vital skill for Elec. Eng. At very least good understanding of C/C++
for lower-level entrenched systems and MATLAB for resolving equations,
analyzing data and designing circuit. Four important aspects of any language
are the way it stores data, the way it operates upon this data, how it
accomplishes input and output, and how it lets you control the
sequence of execution of instructions in a program. C programming
language developed at AT & T’s Bell Laboratories of USA in 1972. It was
designed and written by a man named Dennis Ritchie.

“History: Programming languages started probably in what the late 40s or something like that.
people used to program computers by basically putting in zeros and ones using something like
switches on a console and then or maybe holes and paper tapes something like that, so extremely
tedious awful whatever and so I think the first programming languages were relatively crude
assembly languages where people would basically write a program that would convert mnemonics
like add ADD into whatever the bit pattern was it corresponding to an add instruction and they'd
do the clerical work of figuring out where things were so you could put a name on a location in a
program and the assembler would figure out where that corresponded to when the thing was all
put together and dropped into memory, and they were early on and this would be the late 40s and
very early 50s there were assemblers written for the various machines.

Every different flavor of computer has its own assembly language, so the EDSAC had it, the
Manchester had it, and the IBM whatever 70, 90 or 74 or whatever had its and so on. so everybody
had their own assembly language. assembly languages have their simplest form at least one
instruction per or one assembly language instruction per instruction in the machine's repertoire
and so you have to know the Machine intimately to be able to write programs in it and if you write
an assembly language program for one kind of machine and then you say jeez it's nice I'd like a
different machine start over okay so very bad. so what happened in the late 50s was people realize
you could play this game again and you could move up a level in writing or creating languages that
were closer to the way the real people might think about how to write code and we're I guess
arguably three or four at that time period there was Fortran which came from IBM, which was
formula translation and to make it easy to do scientific and engineering computation. COBOL
which is the common business-oriented language that

Grace Hopper and others worked on which was named business kinds of tasks. there were ALGO
which was mostly meant to describe algorithmic computations. those moved the level up and so
they were closer to what you and I might think of as we were trying to write a program and they
were focused on different domains Fortran for formula translation engineering computations let's
say COBOL for business that kind of thing. but the deal was that once you moved up that level then
you let's call it Fortran you had a language that was not tied to a particular kind of hardware
because a different compiler would compile for different kind of hardware and that meant two
things. it meant you only had to write the program once which is very important and it meant that
you could in fact if you were a random engineer physicist whatever you could write that program
yourself you didn't have to hire a programmer to do it for you might not be as good as you'd get
through a programmer but it was pretty good and so it democratized and made much more
broadly available the ability to write code. in the 70s you get system programming languages of
which C is the survivor. what is system programming language?
programming languages that would take on the kinds of things that would be necessary to write
so-called system programs things like text editors or assemblers or compilers or operating systems
themselves those kinds of things and feature-rich they have to be able to do memory management
access processes. they're much more in touch with the actual machine in a but in a positive way
that is you can talk about memory in a more controlled way you can talk about the different data
types that the Machine supports and underway there and more ways to structure and organize
data and so the system programming languages there was a lot of effort in that and call it the late
60s early 70s C is I think the only real survivor of that and then what happens after that you get
things like object-oriented programming languages because as you write programs in a language
like C at some point scale gets to you and it's too hard to keep track of the pieces and there's no
guardrails or training wheels or something like that to prevent you from doing bad things so C++
comes out of that tradition.”1

Features of C

 procedural programming
 middle level language: direct access to memory through pointers, bit
manipulation using bitwise operations, writing assembly code within C
code
 popular choice for system level apps
 wide variety of built-in functions (printf, scanf, sqrt, strcut, isdigit,
malloc), standard libraries and header files (stdio.h, math.h, string.h,
conio.h, stdlib.h, time.h, ctype.h)

The C character set: A character denotes any alphabet, digit or special


symbol used to represent information.

1
Brian Kernighan (coauthor of C book) talks in Lax Fridman Podcast
Constants, Variables and Keywords: The alphabets, digits and special
symbols when properly combined form constants, variables and keywords. Let
us now understand the meaning of each of them. A constant is an entity
that doesn’t change, whereas a variable is an entity that may change. A
keyword is a word that carries special meaning. C programming do lots of
calculations and the result is stored in memory location. Like human
memory, the computer’s memory also consists of millions of cells. To
make the retrieval and usage of these values easy, these memory cells (also
called memory locations) are given names. Since the value stored in each
location may change, the names given to these locations are called variable
names.
Consider the memory locations shown in Figure below. Here 3 is stored in a
memory location and a name x is given to it. Then we have assigned a new
value 5 to the same memory location x. This would overwrite the earlier value
3, since a memory location can hold only one value at a time.

In programming languages, constants are often called literals, whereas,


variables are called identifiers.
C keywords
Keywords are the words whose meaning has already been explained to the C
compiler (or in a broad sense to the computer). There are only 32 keywords
available in C.
Form of a C Program
Form of a C program indicates how it has to be written/typed. There are
certain rules about the form of a C program that are applicable to all C
programs. These are as under:
(a) Each instruction in a C program is written as a separate statement.
(b) The statements in a program must appear in the same order in which we
wish them to be executed.
(c) Blank spaces may be inserted between two words to improve the
readability of the statement.
(d) All statements should be in lower case letters.
(e) C has no specific rules for the position at which a statement is to be
written in a given line. That’s why it is often called a free-form language.
(f) Every C statement must end with a semicolon ( ; ). Thus ; acts as a
statement terminator.
Comments
It is a good practice to begin a program with a comment indicating the
purpose of the program, its author and the date on which the program was
written. Comments should be enclosed within /* comments here */ or //another
way.
#include<stdio.h> is preprocessor directive, preprocessor replaces the text
(starting with #) with the actual content.
 replaces the compilation begains
 output of preprocessor is extended source code, then compiler changes
it to machine code. source code----->extended source code------>machine
code
 stdio.h: standard input output file, is header file - contains declaration
(prototypes) of functions like printf, scanf etc.
Function and Variable
Code in C consists of function and a variable. Function consists of group of
statements that are intended to solve a particular problem on the other
hand, variables are the entities used to store values which are used
during computation. We can have several functions inside your program but
the entry point where the actual computation begins is the main function.
Syntax of function:
return_type name_of_function(parameter_type name_of_parameter,
parameter_type name_of_parameter, …)
{
Set of statements;
}
Compilation Process
The compilation process in C is converting human understandable code into a
Machine understandable code and checking the syntax and semantics of the
code to determine any syntax errors or warnings present in our C program.
Suppose we want to execute our C Program written in an IDE (Integrated
Development Environment). In that case, it has to go through several phases
of compilation (translation) to become an executable file that a machine can
understand.

Pre-processing is the first step in the compilation process in C performed


using the pre-processor tool (A pre-written program invoked by the system
during the compilation). statments starting with # symbole in a C program are
processed by the pre-processor.
Tasks
 comment removal
 macros expansion (constant values or expressions defined using the
#define directives eg. #define G 9.8)
 file inclusion: addition of another file containing some pre-written code
into our C Program using the #include directive. If we have to use basic
input/output functions like printf() and scanf() in our C program, we
have to include a pre-defined standard input output header file i.e.
stdio.h,
 Conditional Compilation: can be performed using commands like #ifdef,
#endif, #ifndef, #if, #else and #elif

You might also like