0% found this document useful (0 votes)
78 views5 pages

5&6 Marks

The document discusses data types in C and provides examples of integer, floating point, enumerated, void, and derived data types. It then explains recursion with an example program to calculate the factorial of a given number recursively. Various types of constants in C are defined, including integer, real, octal, hexadecimal, character, and string constants. Key differences between keywords and identifiers are outlined. Finally, several string manipulation functions like strlen(), strcpy(), strcat(), strcmp(), strlwr(), and strupr() are explained with code examples.

Uploaded by

sudharsonkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views5 pages

5&6 Marks

The document discusses data types in C and provides examples of integer, floating point, enumerated, void, and derived data types. It then explains recursion with an example program to calculate the factorial of a given number recursively. Various types of constants in C are defined, including integer, real, octal, hexadecimal, character, and string constants. Key differences between keywords and identifiers are outlined. Finally, several string manipulation functions like strlen(), strcpy(), strcat(), strcmp(), strlwr(), and strupr() are explained with code examples.

Uploaded by

sudharsonkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

4) Explain the different data types in C.

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 −

Sr.No. Types & Description

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.

3 The type void


The type specifier void indicates that no value is available.

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

8) Define constant. Describe the various types of constant in C.


C Constants are also like normal variables. But, only difference is, their values cannot be
modified by the program once they are defined. Constants refer to fixed values. They are also
called as literals also Constants may be belonging to any of the data type.

Syntax:

const data_type variable_name; (or) const data_type *variable_name;

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

Constant type data type (Example)

int (53, 762, -478 etc )


unsigned int (5000u, 1000U etc)
long int, long long int
Integer constants (483,647 2,147,483,680)

float (10.456789)
Real or Floating point constants doule (600.123456789)

Octal constant int (Example: 013 /*starts with 0 */)

Hexadecimal constant int (Example: 0x90 /*starts with 0x*/)

character constants char (Example: „A‟, „B‟, „C‟)

string constants char (Example: “ABCD”, “Hai”)

9) Differentiate between identifier and keywords with Examples

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.

Format Consider only letters. Consider letters, underscore, digits.


BASIS FOR
KEYWORD IDENTIFIER
COMPARISON

Case Use only lowercase. Lower and upper cases, both are allowed.

Symbol No special symbol, punctuation No punctuation or special symbol except


is used. 'underscore' is used.

Classification Keywords are not further Identifier are classified into 'external name'
classified. and 'internal name'.

Starting letter It always starts with a First character can be a uppercase,


lowercase letter. lowercase letter or underscore.

Example int, char, if, while, do, class etc. Test, count1, high_speed, etc.

6mark
Explain any five string manipulation library functions with examples

Function Work of Function

strlen() computes string's length

strcpy() copies a string to another

strcat() concatenates(joins) two strings

strcmp() compares two strings

strlwr() converts string to lowercase

strupr() converts string to uppercase


#include <stdio.h>
#include <string.h>
void main () {
char str1[12] = "Hello";
char str2[12] = "World";
char str3[12];
int len ;
strcpy(str3, str1);
printf("strcpy( str3, str1) : %s\n", str3 );
strcat( str1, str2);
printf("strcat( str1, str2): %s\n", str1 );
len = strlen(str1);
printf("strlen(str1) : %d\n", len );
printf(strlwr(str1));
printf(strupr(str2));
}

Output:
strcpy( str3, str1) : Hello
strcat( str1, str2): HelloWorld
strlen(str1) : 10
hello
WORLD

You might also like