5&6 Marks
5&6 Marks
Data types in c refer to an extensive system used for declaring variables or functions of different
types. The type of a variable determines how much space it occupies in storage and how the bit
pattern stored is interpreted.
The types in C can be classified as follows −
1 Basic Types
They are arithmetic types and are further classified into: (a) integer types and (b) floating-point
types.
2 Enumerated types
They are again arithmetic types and they are used to define variables that can only assign certain
discrete integer values throughout the program.
4 Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e)
Function types.
7) What is recursion? Write a program to find the factorial of a given number using recursion.
The C programming language supports recursion, i.e., a function to call itself. But while using
recursion, programmers need to be careful to define an exit condition from the function,
otherwise it will go into an infinite loop.
Recursive functions are very useful to solve many mathematical problems, such as calculating
the factorial of a number, generating Fibonacci series, etc.
Number Factorial
Example Program:
Live Demo
#include <stdio.h>
int factorial(int i) {
if(i <= 1) {
return 1;
}
return i * factorial(i - 1);
}
void main() {
int i = 12;
printf("Factorial of %d is %d\n", i, factorial(i));
}
Output:
Factorial of 12 is 479001600
Syntax:
TYPES OF C CONSTANT:
1. Integer constants
2. Real or Floating point constants
3. Octal & Hexadecimal constants
4. Character constants
5. String constants
6. Backslash character constants
float (10.456789)
Real or Floating point constants doule (600.123456789)
BASIS FOR
KEYWORD IDENTIFIER
COMPARISON
Basic Keywords are the reserved Identifiers are the user defined names of
words of a language. variable, function and labels.
Use Specify the type/kind of entity. Identify the name of a particular entity.
Case Use only lowercase. Lower and upper cases, both are allowed.
Classification Keywords are not further Identifier are classified into 'external name'
classified. and 'internal name'.
Example int, char, if, while, do, class etc. Test, count1, high_speed, etc.
6mark
Explain any five string manipulation library functions with examples
Output:
strcpy( str3, str1) : Hello
strcat( str1, str2): HelloWorld
strlen(str1) : 10
hello
WORLD