Variable,datatypes,input and output Flashcards

1
Q

what is the command to run a c program without using the run command?

A

gcc filename.c
./a.exe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are different rules to be considered while naming a variable?

A

variables are case sensitive (a and A are different)
1st character is alphabet or “
no comma or blank space allowed
only symbol allowed is “

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

write c code for different types of variables?

A

int a=22;
char name=”sam”;
float pi=3.14;

updating variable
a=45;
does not require to initialize the datatype again

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is byte and bit?

A

1 byte = 8 bit
1 bit can be either 0 or 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how many memory does each datatype consume

A

char - 1 byte
int -2 byte
float -4 byte

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are different types of constants in c

A

integer constant -1,2,3
real constant -1.0,2.0
char constant -“a”,”A”,”&”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are key words in c

A

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..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

example for preprocessor directive

A

<stdio.h>
</stdio.h>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is the structure of a C program

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what are the code for comments in C

A

// single line
/* */ multi line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

code for new line in C

A

printf(“hello world\n”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

code to print different types of datatypes in C

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

code for taking input from user

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

program to add two numbers

A

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; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

program to add two numbers

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

compilation and compiler

A

compilation is a computer program that translates c code into machine code

hello.c——>compiler(check for syntax error)——>a.exe(for windows),a.out(for mac & linux) which the computer understands

16
Q

program to find area of a square

A

include<stdio.h></stdio.h>

int main(){
int side;
printf(“enter side :”);
scanf(“%d”,&side);
printf(“area is %d”,side*side);
return 0;
}

17
Q

program to find area of circle

A

include<stdio.h></stdio.h>

int main(){
int radius;
float pi=3.14;
printf(“enter radius of circle :”);
scanf(“%d”,&radius);
printf(“area of circle is %f”,piradiusradius);
return 0;
}