Overview of C
C is developed by Dennis Ritchie
• C is a structured
programming language
• C preferred those functions that enables easy maintainability
of code, by breaking large file into smaller modules.
• Generally Comments in
C programming language gives easy
readability.
A sample C Program
#include<stdio.h>
main()
{
-- statements
// Comments
}
Header files:
• The files which are defined
in the include section is called as header file.
• These files are
called precompiled files which has some functions defined in them
• These functions can
be called in the program by supplying parameters.
• Header files are
defined with an extension .h
• The Source file of C programming
is given an extension .c
main functions:
• It is recognized as
start of a program
•In time of file
execution, the beginning of any program is the main function.
• From main function
the flow of the program goes as per the programmer’s choice.
• There might be other
functions written by user in a program
• without Main function
a c program cann’t be written.
Sample program:
#include<stdio.h>
main ()
{
printf(“Ram”);
getch();
}
• This program prints
“Ram” on the screen when it will executed.
How to run a C
program
• First Type a program
• Save it
• Then Compile the
program – It will generate an exe file (executable)
• Run the program (That
exe created out of Compilation will run and not the .c file)
• In several compilers
we've different option for Compiling and running. We give only the Concepts.
7. Comments in C:
• Single line comment
– // (double slash)
– Termination of comment is by pressing enter
Key
• Multi line comment
/*….
…….*/
This can span over to multiple lines
8. Data types in C:
• Primitive data types
– int, float, double, char
• Aggregate data types
– Arrays come under this category
– Arrays data type could be a collection of int or float or
char or double data
• User defined data types
– Structures and enum fall under this category.
9. Variable:
• Variables are data which will keep it up changing
• Declaration
;
int b;
• Definition
a=10;
• Usage
b=b+1; //increments the value of a by 1
10. Variable name rules:
• shouldn't be a reserved word like int etc..
• Should start with a letter or an
underscore(_)
• Can contain letters, numbers or
underscore.
• No other special characters are allowed
including space
• Variable names are case sensitive
–A and a aredifferent.
11.Input and output:
• Input
–scanf(“%d”,&a);
– Any type of value from the user can be
Stored in the name of “a”
• Output
– printf(“%d”,a);
– Prints the worth present in variable a on the
screen
12. Operators:
• Arithmetic (+,-,*,/,%)
• Relational (>=,<=,==,!=)
• Logical (&&,||,!)
• Bitwise (&,|,^,~,<<,>>)
• Assignment (=,+=,-=,*=,/=,%=,<=,>=,&=,^=,|=)
• Shift (right shift >>, left shift <<)
12. String functions:
strlen(str) – To find length of string str
strrev(str) – Reverses the string str as rts
strcat(str1,str2) – this function appends str2 to str1 and returns str1
strcpy(st1,st2) – It copies the content of st2 to st1
strcmp(s1,s2) – It compares the two string s1 and s2
strcmpi(s1,s2) – It is case insensitive comparison of strings
13.Numeric functions:
abs(num) – It returns a absolute value
log(x) -It Logarithmic value
sin(x):Sine value
cos(x):cosine value
tan(x):tan value
14.C keywords and identifiers:
here you will get to know about keywords; reserved words in C programming language that are part of the syntax.. Also get to know how to write indentifiers. Here it is given below..
C Identifiers:
Character set
In c programming, character set is a set of alphabets, letters and some special characters.
Alphabets
Uppercase: A B C ................................... X Y Z
Lowercase: a b c ...................................... x y z
C accepts both lowercase and uppercase alphabets as variables and functions.
Digits
0-9
Special case characters, white space characters
Identifier refers to call given to entities
like variables, functions, structures etc. Identifiers must be unique. they're
created to administer a singular name to an entity to spot it during the
execution of the program. For example: int money; double accountBalance; Here,
money and accountBalance are identifiers. Also remember, identifier names must
vary from keywords. you can't use int as an identifier because int could be a
keyword. Rules for naming identifiers.It cannot be used like keywords eg. int, while etc. as
identifiers.
C keywords:
Keywords
are predefined, reserved words employed in programming that have special
meanings to the compiler. Keywords are part of the syntax and that they cannot
be used as an identifier. For example: int mango; Here, int could be a keyword
that indicates mango could be a variable of type int (integer). As C may be a
case sensitive language, all keywords must be written in lowercase. Here could
be a list of all keywords allowed in ANSI C.
C Keywords are given here i.e. Auto,double, int ,struct ,break ,else ,long ,switch case ,enum register, type def ,char ,extern ,return ,union ,continue, for ,signed ,void ,do, if ,static ,while ,default goto ,sizeof ,volatile ,const ,float ,short ,unsigned.
Video tutorial on C Programming overview:
Examples of C programs(see the full program click on the below given links)
1.Write a c program to swap two numbers.
2.C program to find Roots of a Quadratic Equation
3.C program to Check it is Leap Year or not
4.C program to check Positive or Negative Using if...else
5.Sum of Natural Numbers Using for Loop
Comments
Post a Comment