Variable,datatypes,input and output Flashcards
what is the command to run a c program without using the run command?
gcc filename.c
./a.exe
what are different rules to be considered while naming a variable?
variables are case sensitive (a and A are different)
1st character is alphabet or “”
no comma or blank space allowed
only symbol allowed is “”
write c code for different types of variables?
int a=22;
char name=”sam”;
float pi=3.14;
updating variable
a=45;
does not require to initialize the datatype again
what is byte and bit?
1 byte = 8 bit
1 bit can be either 0 or 1
how many memory does each datatype consume
char - 1 byte
int -2 byte
float -4 byte
what are different types of constants in c
integer constant -1,2,3
real constant -1.0,2.0
char constant -“a”,”A”,”&”
what are key words in c
keywords are reserved words that have special meaning to the compiler
they must not be used for naming
there are 32 keywords in c
eg:int,char,float,if,return etc..
example for preprocessor directive
<stdio.h>
</stdio.h>
what is the structure of a C program
include<stdio.h></stdio.h>
int main() {
printf(“hello”);
return 0;
}
after main() the program or statement to be executed is written and it is executed line by line
; is used as a statement terminator ,can write code side by side after;
return 0 denotes 0 error has been encountered
<stdio.h> is preprocessor directive
</stdio.h>
what are the code for comments in C
// single line
/* */ multi line
code for new line in C
printf(“hello world\n”);
code to print different types of datatypes in C
integer
printf(“ age is %d”,age);
d- double value
real number
printf(“ value of pi is %f”,pi);
f-float
character
printf(“star look like this %c”,star);
c-char
here %d,%f,%c are called format specifiers
code for taking input from user
scanf(“%d”,&age)
%d specifies the type of input
&age- denote the address and variable name in which the input must be stored
int age; printf("enter age :\n"); scanf("%d", &age);45 printf("age is %d",age);
the variable and datatype must be initialized before
program to add two numbers
include<stdio.h></stdio.h>
int main() {
int a,b;
printf(“enter a :\n”);
scanf(“%d”,&a);
printf("enter b :\n"); scanf("%d",&b); int sum =a+b; printf("sum is %d",sum); return 0; }
program to add two numbers
include<stdio.h></stdio.h>
int main() {
int a,b;
printf(“enter a :\n”);
scanf(“%d”,&a);
printf("enter b :\n"); scanf("%d",&b); int sum =a+b; printf("sum is %d",sum); return 0; }
or you can use a+b directly without using sum variable