C programming 2021
C programming Introduction
It is really very easy to learn so move forward.....
C programming is a basic programming language, which is procedure oriented language that means this c language is all works on functions only like main function and other predefined or user-defined functions.
C programming mainly consists of pre processor and functions, some data types as well as variables.
Example---- :
Program is as follows,,,,
#include<stdio.h>
void main()
{
int a=2;
printf("%d",a);
}
Output :2
In that pre processor we use *include* this is command , which works the including to program. And also mainthing is header files , the header files consists of pre defined functions like printf ,scanf,pow,strrev..... Examples of header files are stdio.h, math.h,stdlib.h..........
Examples-------:
1. #include<stdio.h>
2.#include<stdlib.h>
3.#include<math.h>
In that function, we can write main function in that we use parameters or else we can leave that empty that is no parameters function. And also we can use return type integers or float or void. Void means we can't return anything. Default return type of any function is integer only. If we declare as integer then we can return 0 or any value.
Examples-----
1. int main(a,b)
Here a,b are parameters
Int is return type of function
main is name of function
2.int main()
In this no parameters given, then there is no problem in that.
Data types in C programming Language
After the function in c programming we have to use curly braces. In that braces we can write statement what ever we want to do. And next , we have to mind one thing that is every statement must ends with semicolon (;).
Example------
int i;
Here it is data type and this whole thing is statement
In that printf and scanf are the input and output function, which are returning integer values only, these two are predefined functions.
And also main part to learn in c programming is data types that is as follows....
1.int
2.float
3.double
4.char
1.int:--
int is one the data type in c programming those are indication of integer values only.
In that int we have signed integer and unsigned integer. These two integer data type difference making at ranges. In unsigned we don't have negative ranges that means starts from zero. In this long int and short two types are there in the integers.
Examples------ int i;
int i=5;
2. Float: -----
These is used for the float values which are having pricision of 6 digits.
Example----
1.float t;
2.float t=5.0000;
3.float r=5.6;
3.double:---
This is another one for float values but the difference is how many digits after point or decimal values. In this precision value is 15 digits
Example------
A.double a;
B.double b=6.89999926762;
4.char::::
Char is used to represent a character and in c programming language we don't have string data type that's why we use char array as string. In this signed and unsigned char is there for address only. This is starts from -128 to +127. This is 1 byte address data type.
In this way we have data types , which are predefined data types. We have some user defined data types , those are structures, union.
Variables in C programming language
A small task for you all.... That is please comment output of the below program
#include<studio.h>
void main()
{
int a=054;
printf("%d",a);
}
What is output of this code..........?
4*8^0+5*8^1=44
Because it is octal number by placing 0 in front of number.
I hope you clear. If there is any doubt please comment...
Next topic of c programming is operators
Those are classified as follows
1. Arithmetic operators
2. Logical operators
3. Relational operators
4. Assignment operators
5. Bit wise operators
6. Increment operators
7. Decrement operators
1. Arithmetic operators:-
These are mainly used for doing arithmetic operations. That is addition, subtraction, multiplication , Division.
Signs are +,-,/,*
Ex:- a+b;
a-b;
a*b;
a/b; // it returns divisible value
Note:
a%b; // it returns remainder
2. Logical operators:-
These are used for logical operations like AND,OR,NOT,XOR...etc.
Signs are &&,||,!, .. etc
Ex:-a&&b
In this condition both non zero then only true otherwise false
a||b
In this condition one of two is non zero or true then true otherwise false
!a
In this , if a is 0 then it makes 1, If a is 1 then 0
3. Relational operators:-
These are used for making comparisons in that condition. Signs are < ,>,<= ,>=
Ex:-
a>b;
a<b;
a<2;
a<=3;..
etc
4. Assignment operators:-
These are used for assign some values to the variables in c programming.
Sign is =.
Ex:- a=2;
a+=2;
5. Bit wise operators:-
These are used to make the operation in bit wise. In this the give number is divided into it's binary format then operation will done.
Signs are &,|,^ etc
Ex:-
a&b;
a|b;
6. Increment operators:-
This is one of the operator commonly use in programming. When we want to increase one value each time.sign is ++; That is as follows
Ex:-
a++;
This means a=a+1;
7. Decrement operators:-
If we want to decrement in each step by one only then this operator is apt for that. This sign is --. Double subtraction sign.
This is as follows example
Ex:-
a--;
This equal to a=a-1;
This is over all operators. Thank you for reading..
Next post will be on keywords...
Here I am giving one program please solve and comment the output below....
#include<studio.h>
int main()
{
printf("%c",~("b"*-1));
return 0;
}
Output :. ?????????
In downside I will give you output...........
C Programming keywords - points:
1. Keywords in c are predefined words in c
2. All keywords are in lower case only. Because c language is case sensitive.
3. These keywords can't be used as variables
4. Keywords in c also called as reserved words
5. In c we have 32 keywords.
List of 32 keywords in c:-
1.int
2.float
3.double
4.long
5.short
6.extern
7.register
8.static
9.auto
10.if
11.else
12.switch
13.for
14.struct
15.union
16.do
17.case
18.default
19.while
20.break
21.return
22.signed
23.unsigned
24.typedef
25.char
26.const
27.continue
28.goto
29.void
30.sizeof
31.volatile
32.enum
These are the keywords of c language.
Below I am giving one program please comment output below..
#include<studio.h>
void main()
{
int a=2;
printf("%d",a++);
}
Output give you in downside.
output is 2
Now we are going to learn about header files.
HEADER FILES
Header files are very important in c programming language because these header files consists of predefined functions like printf(),scanf(),pow()....etcThere we have more header files in that we learn here some which are some what important...
1.stdio.h
In this header file consists of address of Function that is printf() and scanf() functions addresses.
This means standard input and output.
2.conio.h
Next of above header file we use this.
In this we have two main functions definition those are clrscr(), getch(),getche()
3.stdlib.h
This is standard library header file. In this we have dynamic memory allocation functions definition ,those are malloc, calloc, realloc, free. And also delay(),rand(),abs(),exit() functions definition are there in this library.
4.math.h
This header file consists of all mathematical functions definition, those are floor(),round(),ceil(),sin(),cos(), cosh(), sinh(), pow()....etc.
Note:- In this floor (3.5)= 3
ceil of 3.5 is 4
5.time.h
In this we use related to time that is setdate(),getdate(),clock(),time() ...etc
6.signal.h
In this we use signal(),raise()..etc
7.errno.h
In this errno() function definition is there.
8.ctype.h
It consists of isgraph() function definition.
And also ispunct(),isdigit(),isalpha().
9.unistd.h
It consists of sleep() function definition. This function is used to make some delay in the execution.
10. string.h
This is exclusive for strings ( array of characters) that is strcpy(),strrev(),strcmp(),strcat(),strlwr(),strupr(),..etc.
Like we have limits.h for string...etc
Today's programs ...
Please comment output of this programs...
1.#include<studio.h> void main() { int a= 2; printf("%d",++a);
} Output :-
2.#include<studio.h>
#include<math.h> void main() { int a= ceil(4.5); printf("%d",a); } Output:-...
1. 3
2. 5
1. 3
2. 5
Now we are going to learn about macros in c programming
MACROS
1. Define something with their alias names then we use #define
2. Header files
3. Conditional
4. If there is defined something previously that can be remove defined that is by using #undefined
Give the output below in comment section
#include<studio.h>
#define n 15
void main()
{
printf("%d",n);
}
Output:-
Array defined as it is a collection of similar data type elements.
data types we discussed previously...
Array is having two major parts taht is size and index
Index is point where the particular data is occur.
Size is total number of elements.
But the most important thing is array start from zero index...
Types of arrays are....
1. Single index array - common array
2. Double index array - matrix array
3. Multi index array
The above all divide by the index parameter
string is a character of array. that in this we can represent characters.
for example char s[20] means that we can write a word of character up to 19 characters.
strings data also starts from zero index on wards but the difference is to find some operations we have predefined functions like strlen(), strcpy()...etc
string can be consist of special characters.
in fact in c programming there is no such data type to indicate strings directly...
for example one program to find length of the string ....
#include<stdio.h>
void main()
{
char s[10];
scanf("%c",&s);
int n=0;
n=strlen(s);
printf("%d",n);
}
More information about C Programming Language will be added soon.
Comments
Post a Comment