Part A (2 Marks)
1)Write a Short note on Keywords?
Keywords are predefined, reserved words in C language
and each of which is associated with specific features.
2) Different Kinds of Datatypes?
Type of data that we are going to access within a
program
Each data type has a predefined memory requirement
and storage representation
Data Types in C
Types Data Types
Basic Data Type int, char, float, double
Derived Data Type array, pointer, structure, union
Enumeration Data Type enum
Void Data Type Void
3)What are various type of Operators?
C supports set of operators used in an expression
Classification of Operator:
Based on Operands –unary(+,-,++,--%,*,/)
Binary(>,<,<=,>=,&&,||)
Ternary(?:)
Based on role of Operators – Arithmetic
Relational
Equality
Logical
Conditional
Bitwise
4)Difference between the statements = and== in C?
The '=' is the so-called assignment operator and is used
to assign the result of the expression on the right side of
the operator to the variable on the left side.
The '==' is the so-called equality comparison operator and
is used to check whether the two expressions on both
sides are equal or not.
Example a=5 :means the value 5 will be stored in the variable 'a'
a==.5: means is used for comparison. It means if the value
of a is equal to 5 then it will return true as output.
5) Write a for loop to print from 10 to 1?
#include<stdio.h>
int main()
{
int i;
for(i=0;i>0;i++)
{
printf(“%d”,i);
}
return 0;
6)What is the Syntax for Array Declararion?
Syntax : data_type array_name[array_size]
Size specifier specifies the number of elements in an array
Memory space is allocated at the compile time
Example
7)Different ways of initializing an array?
Array initialization
Arr[5]={2,4,8.12.16};
Memory allocated and initialized
2 4 8 12 16
A[0] A[1] A[2] A[3] A[4]
Different ways:
Method 1: By using an initialiser list arr[5]={1,2,3,4,5}
Method 2: Without giving array size arr[]={1,2,3,4,5}
Method 3 : Using designated initialize list,to selectively initialize the
range of elements int arr[5];
arr[0]=1;arr[1]=2;arr[2]=3;arr[3]=4;arr[4]=5;
Method 4 : By using for loop int arr[5];
for(i=0;i<5;i++)
{
scanf(“%d”,arr[i]);
}
8)Dafine a float array of size 5 and assign 5 values to it?
Float array: Is a grouping of numerical data containing
floats,numbers with fractional value.
For 5 float values ,if float takes 4 bytes then this
array will take 20 bytes of memory.
arr[5]={1.2,3.4,5.6,7.8,9.1};
1.2 3.4 5.6 7.8 9.1
a[0] a]1] a[2] a[3] a[4]
9)How to create two dimensional array?
Syntax : data type array name[row size][column size] ;
The elements of a two dimensional array can be accessed by
using a row subscript and column subscript
2 1 2 4 5
1 6 8 5 4
2 7 2 4 8
6 3 1 1 0
Applications : Used in seating arrangement
Used to park or find vehicle in large parking areas
10)Show a C function to compare two strings ?
Function : strcmp()
The function performs the comparison of two strings
character by character until the corresponding characters
differ or the end of the string is reached.
Returns the ASCII difference if mismatch or returns zero if
same.
Syntax : strcmp(string1,string 2);
Eg: char s1[5]=”Hello”
char s2[5]=”Good” Output = -1
n=strcmp(s1,s2);
printf(“%d”,n);