Basic and important Data types in C.
- Integer type :- Integer data type in c are used to store integer values. "int " followed by a name is used to declare a integer type of variable.
- Float type :- Float type is used to store a number with a decimal point. Declared with a keyword "float" followed with a name.
- Example
- float b;
- b=2.34;
- float b=2.34;
- Character type :- Character type is used to store a single alphabet. Declared with a keyword "char" followed by the variable name. The character to be stored in the variable should be inside double or single quotation marks.
- Example
- char a='c',
- char b;
- b="a";
- Long and Double :- long is used when the number is large enough that space for int type is not sufficient. Double is in case of float for large decimal point numbers.
- Example
- long i=1223434545647;
- double num=123545.423534545645;
- Comments in C
- // (two back slash) are used to comment a line in the code.
- /* comments */ are used to comment a bunch of lines at a time.
- "scanf ( )" Function
- scanf function is used to take inputs from users depending on variables data types.
- %d used for integers
- %f used for floating point numbers
- %c for characters
- #include<stdio.h>
- int main()
- {
- int num1; //declared a integer variable
- float num2; //declared a float variable
- char alp; //declared a character variable
- printf("enter values"); //taking input from user
- scanf("%c",&alp); //to take character from user
- scanf("%d",&num1); //used to take integer value from user.
- scanf("%f",&num2); //to take float value from user
- printf("INTEGER VALUE= %d\n",num1); //used to display
- printf("FLOAT VALUE= %f\n",num2);
- printf("CHARACTER VALUE= %c\n",alp);
- return 0;
- }
CODE OUTPUT:-
No comments:
Post a Comment