Beruflich Dokumente
Kultur Dokumente
9. Define String.
A string in C is merely an array of characters. The length of a string is determined by a
terminating null character: '\0'. So, a string with the contents, say, "abc" has four characters: a, b, c,
and the terminating null character. Eg: char name [ ] = {a,b,c,\0}; or char name[ ]=abc;
10. What is the use of strcat() function?
The strcat() function joins two strings. Its a library function, and has its declaration in string.h header
file. Eg: strcat(s1,s2) It shall append a copy of the string pointed to by s2 to the end of the string pointed
to by s1.
#include <stdio.h>
#include <string.h>
int main()
{
char a[10], b[10];
printf("\n Enter the first string: ");
gets(a);
printf("\n Enter the second string: ");
gets(b);
strcat(a,b);
printf("String obtained on concatenation is %s\n",a);
}
Output:
Enter the first string: hello
Enter the second string: world
String obtained on concatenation is helloworld
11. How does array variable differ from an ordinary variable?
Array variable can store group of elements of the same data type under a common name where
as ordinary can be able to store only one value at a time.
Example: int a; // variable a can store single integer value
int a[5]; // here in a we can save 5 integer values
{
char str[100];
int length;
printf("\nEnter the String : ");
gets(str);
length = 0; // Initial Length
while (str[length] != '\0')
length++;
printf("\nLength of the String is : %d", length);
return(0);
}
19. What is meant by Sorting?What are its types?
Sorting refers to ordering data in an increasing or decreasing fashion according to some linear relationship
among the data items. Sorting can be done on names, numbers and records.
Types of sorting available in C:
Insertion sort.
Merge Sort.
Quick Sort.
Radix Sort.
Heap Sort
Selection sort
Bubble sort
20. Define Searching.
Searching for data is one of the fundamental fields of computing. Search is an operation in which a given
list is searched for a particular value.the location of the searched element is informed.
Various types of searching techniques in C are
Linear search
Binary search
21. What is Binary Search?
A search algorithm which repeatedly divides an ordered search array in half and compared the required
search value with the middle element of the array.
If the search value is equal to middle element then it returns the middle element.
If the search value is less than the middle element it Searches only from low to mid-1.
If the search value is greater than the middle element it Searches only from mid+1 to high.
UNIT-IV
c
5
2000
3000
ptr
2000
#include<conio.h>
int sum(int n);
void main()
{
int n;
printf("How many terms ?:");
scanf("%d",&n);
printf("Sum of First %d Natural Number=%d",n,sum(n));
getch();
}
int sum(int n)
{
int i,sum=0;
for(i=1; i<=n; i++)
sum+=i;
return sum;
}
Output
How many terms ?:10
Sum of First 10 Natural Number=55
20. What are the rules to be followed for performing pointer operations?
One can perform different arithmetic operations on pointer such as increment, decrement but still we have
some more arithmetic operations that cannot be performed on pointer as follows:
Addition of two addresses.
Multiplying two addresses.
Division of two addresses.
Modulo operation on pointer.
Cannot perform bitwise AND,OR,XOR operations on pointer.
Cannot perform NOT operation or negation operation.