SlideShare a Scribd company logo
D.E.I. TECHNICAL COLLEGE
COURSE TITLE: Software Development-VI
SLIDE-2
COURSE CODE: VIT351
CLASS: DIPLOMA IN INFORMATION TECHNOLOGY VOCATIONAL (1ST YEAR)
SESSION: 2019-20
TOPICS COVERED
 ARRAYS IN C
 MULTIDIMENSIONAL ARRAYS
 CHARACTER HANDLING IN C
 STRING HANDLING IN C
 QUIZ SET 2
What is an Array?
 Arrays are the collection of a finite number of homogeneous
data elements.
 Elements of the array are referenced respectively by an
index set consisting of n consecutive numbers and are
stored respectively in successive memory locations.
 The number n of elements is called the length or size of the
array.
GO TO TOPICS
Continue….
 Array is a collection of similar elements. These similar elements
could be all ints, floats, doubles, chars, etc. Array is also known as
subscript variable.
 Array can store a fixed-size sequential collection of elements of
the same type.
 Array elements are stored in contiguous memory block.
 Instead of declaring individual variables, such as number0,
number1, ..., and number99, you can declare one array variable.
 Creating array is creating a group of variables and all its elements
are accessed via single name and different subscript values.
Properties of an Array
1) Indexing of an array begins from zero (0).
2) The variable name of array contains the base address of
the memory block.
3) The array variable are created at the time of
compilation.
4) The size of the array cannot be altered at runtime.
How to declare an Array?
Syntax:
dataType arrayName[arraySize];
For example,
float mark[5];
This is called single dimensional array.
Here, we declared an array, mark, of floating-point type.
And its size is 5. Meaning, it can hold 5 floating-point values.
It's important to note that the size and type of an array cannot
be changed once it is declared.
 Array declaration by specifying size
// Array declaration by specifying size
int arr1[10];
// With recent C/C++ versions, we can also
// declare an array of user specified size
int n = 10;
int arr2[n];
 Array declaration by initializing elements
// Array declaration by initializing elements
int arr[] = { 10, 20, 30, 40 }
// Compiler creates an array of size 4.
// above is same as "int arr[4] = {10, 20, 30, 40}"
 Array declaration by specifying size and
initializing elements
// Array declaration by specifying size and
initializing elements
int arr[6] = { 10, 20, 30, 40 }
// Compiler creates an array of size 6,
initializes first
// 4 elements as specified by user and rest
two elements as 0.
// above is same as "int arr[] = {10, 20, 30, 40,
0, 0}"
How to access an Array?
 Array elements are accessed by using an integer index.
 Index of an array starts from 0 to size-1 i.e first element of arr array will be stored at arr[0]
address.
Example:
#include <stdio.h>
int main()
{
int arr[5];
arr[0] = 5;
arr[2] = -10;
arr[3 / 2] = 2; // this is same as arr[1] = 2
arr[3] = arr[0];
printf("%d %d %d %d", arr[0], arr[1], arr[2], arr[3]);
return 0;
}
Initialization of an Array
 After an array is declared it must be initialized. Otherwise, it will
contain garbage value(any random value). An array can be initialized at either compile
time or at runtime.
data-type array-name[size] = { list of values };
/* Here are a few examples */
int marks[4]={ 67, 87, 56, 77 }; // integer array initialization
float area[5]={ 23.4, 6.8, 5.5 }; // float array initialization
int marks[4]={ 67, 87, 56, 77, 59 }; // Compile time error
In such case, there is no requirement to define the size. So it may also be written as the
following code.
int marks[]={20,30,40,50,60};
Example:
#include <stdio.h>
int main()
{
int marks[10], i, n, sum = 0, avg;
printf("Enter number of elements: ");
scanf("%d", &n);
for(i=0; i<n; i++)
{
printf("Enter number");
scanf("%d", &marks[i]);
// adding integers entered by the user to the sum variable
sum =sum+marks[i];
}
avg = sum/n;
printf("Average = %d", avg);
return 0;
}
Multi-dimensional Array
 C language supports multidimensional arrays also.
 The simplest form of a multidimensional array is the two-dimensional array.
 Both the row's and column's index begins from 0.
Declaration:
data-type array-name[row-size][column-size]
/* Example */
int a[3][4];
GO TO TOPICS
Initialization of 2-D Array
 int b[2] [3] = {12,65,78,45,33,21}; //valid
 int b[ ] [3] = {12,65,78,45,33,21}; // valid
 int b[2] [ ] = {12,65,78,45,33,21}; //invalid
 int b[ ] [ ] = {12,65,78,45,33,21}; // invalid
Example: Adding two matrices
#include <stdio.h>
int main()
{ int i,j;
int a[2][2], b[2][2], result[2][2];
// Taking input using nested for loop
printf("Enter elements of 1st matrixn");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++){
printf("Enter a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]); }
// Taking input using nested for loop
printf("Enter elements of 2nd matrixn");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++){
printf("Enter b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}
// adding corresponding elements of two arrays
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
{
result[i][j] = a[i][j] + b[i][j];
}
// Displaying the sum
printf("nSum Of Matrix:n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
{
printf("%dt", result[i][j]);
if (j == 1)
printf("n");
}
return 0;
}
Important Note:
 The array elements can be accessed in a constant time by using the index of the
particular element.
 To access an array element, address of an element is computed as an offset
from the base address of the array and one multiplication is needed to compute
what is supposed to be added to the base address to get the memory address
of the element
 First the size of an element of that data type is calculated and then it is multiplied
with the index of the element to get the value to be added to the base address.
 This process takes one multiplication and one addition. Since these two
operations take constant time, we can say the array access can be performed
in constant time.
Dealing with Characters
ctype.h file includes functions that are useful for testing and
mapping characters.
All the functions defined in ctype.h accept int as a
parameter, whose value must be EOF or representable as
an unsigned char.
These functions return non-zero (true) if the argument
satisfies the condition described else the functions return
zero (false).
GO TO TOPICS
isalnum() Function
 Description
The C library function void isalnum(int c) checks if the passed
character is alphanumeric.
 Declaration
int isalnum(int c);
 Parameters
c − This is the character to be checked.
 Return Value
This function returns non-zero value if c is a digit or a letter, else it
returns 0.
Example:1#include <ctype.h>
#include<stdio.h>
int main () {
int var1 = 'a';
int var2 = '4';
int var3 = 't';
if( isalnum(var1) ) {
printf("var1 = |%c| is alphanumericn", var1 );
} else {
printf("var1 = |%c| is not alphanumericn", var1 ); }
if( isalnum(var2) ) {
printf("var2 = |%c| is alphanumericn", var2 );
} else {
printf("var2 = |%c| is not alphanumericn", var2 ); }
if( isalnum(var3) ) {
printf("var3 = |%c| is alphanumericn", var3 );
} else {
printf("var3 = |%c| is not alphanumericn", var3 ); }
return(0); }
isalpha() Function
 Description
The C library function void isalpha(int c) checks if the passed
character is alphabet.
 Declaration
int isalpha(int c);
 Parameters
c − This is the character to be checked.
 Return Value
This function returns non-zero value if c is a letter, else it returns 0.
Example:2#include <stdio.h>
#include <ctype.h>
int main () {
int var1 = 'a';
int var2 = '4';
int var3 = 't';
if( isalpha(var1) ) {
printf("var1 = |%c| is an alphabetn", var1 );
} else {
printf("var1 = |%c| is not an alphabetn", var1 );}
if( isalpha(var2) ) {
printf("var2 = |%c| is an alphabetn", var2 );
} else {
printf("var2 = |%c| is not an alphabetn", var2 );}
if( isalpha(var3) ) {
printf("var3 = |%c| is an alphabetn", var3 );
} else {
printf("var3 = |%c| is not an alphabetn", var3 );}
return(0); }
iscntrl() Function
 Description
The C library function void iscntrl(int c) checks if the passed character
is a control character.
 Declaration
int iscntrl(int c);
 Parameters
c − This is the character to be checked.
 Return Value
This function returns non-zero value if c is a control character, else it
returns 0.
Example:3#include <stdio.h>
#include <ctype.h>
int main ()
{
int i = 0, j = 0;
char str1[] = "We like to learn a about t programming";
char str2[] = "these tutorials n are nice";
/* Prints string till control character a */
while( !iscntrl(str1[i]) )
{
putchar(str1[i]);
i++;
}
/* Prints string till control character n */
while( !iscntrl(str2[j]) )
{
putchar(str2[j]);
j++;
}
return(0);
}
isdigit() Function
 Description
The C library function void isdigit(int c) checks if the passed
character is a decimal digit character.
Decimal digits are (numbers) − 0 1 2 3 4 5 6 7 8 9.
 Declaration
int isdigit(int c);
 Parameters
c − This is the character to be checked.
 Return Value
This function returns non-zero value if c is a digit, else it returns 0.
ispunct() Function
 Description
The C library function int ispunct(int c) checks whether the passed
character is a punctuation character. A punctuation character is
any graphic character (as in isgraph) that is not alphanumeric (as
in isalnum).
 Declaration
int ispunct(int c);
 Parameters
c − This is the character to be checked.
 Return Value
This function returns a non-zero value(true) if c is a punctuation
character else, zero (false).
isspace() Function
 Description
The C library function int isspace(int c) checks whether the passed character is white-
space.Standard white-space characters are:
 ' ' (0x20) space (SPC)
 't' (0x09) horizontal tab (TAB)
 'n' (0x0a) newline (LF)
 'v' (0x0b) vertical tab (VT)
 'f' (0x0c) feed (FF)
 'r' (0x0d) carriage return (CR)
Declaration
int isspace(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns a non-zero value(true) if c is a white-space character else, zero (false).
String Handling in C
 String is a sequence of characters that is treated as a single data item and terminated by
null character '0'.
 Remember that C language does not support strings as a data type.
 A string is actually one-dimensional array of characters in C language.
 These are often used to create meaningful and readable programs.
 C language supports a large number of string handling functions that can be used to
carry out many of the string manipulations. These functions are packaged
in string.h library.
char name[12] = “DataScience"; // valid character array initialization
char name[12] = {‘d',‘a',‘t',‘a',‘s',‘c',‘i',’e’,’n’,’c’,’e’,'0'}; // valid initialization
char ch[3] = “data"; // Illegal
char str[4];
str = “data"; // Illegal
GO TO TOPICS
 strlen()
o prototype: int strlen(char *);
o It calculates the length of the given string
 strrev()
o prototype: char* strrev(char*);
o It reverses the given string
 strlwr()
o prototype: char* strlwr(char*);
o It converts the given string into its corresponding lower case
 strupr()
o prototype: char* strupr(char*);
o It converts the given string into its corresponding upper case
 strcpy()
o prototype: char* strcpy(char*, char*);
o It copies the second string into first
 strcat()
o prototype: char* strcat(char*, char*);
o It simply appends or concatenates the two strings.
 strcmp()
o prototype: int strcmp(char*, char*);
o It compares two strings and return -1, 0 or 1, indicative values.
Return 0 if strings are identical.
Returns -1 if first string appears before the second string in the dictionary.
Returns 1 if first string appears after the second string in the dictionary.
OR
 if Return value < 0 then it indicates str1 is less than str2.
 if Return value > 0 then it indicates str2 is less than str1.
 if Return value = 0 then it indicates str1 is equal to str2.
Example:1&2#include <stdio.h>
#include <string.h>
int main()
{
char str1[12] = "Hello";
char str2[12] = "Team";
char str3[12];
int len ;
/*copy str1 into str3 */
strcpy(str3, str1);
printf("strcpy(str3, str1) : %sn", str3 );
/*concatenates str1 and str2 */
strcat (str1, str2);
printf("strcat(str1, str2) : %sn", str1 );
/*total lenghth of str1 after concatenation */
len = strlen (str1);
printf("strlen(str1) : %dn", len );
return 0;
}
#include <stdio.h>
#include <string.h>
int main ()
{
char src[50], dest[50];
strcpy(src, "This is source");
strcpy(dest, "This is destination");
strcat(dest, src);
printf("Final destination string : |%s|", dest);
return(0);
}
Example:3
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[15];
char str2[15];
int ret;
strcpy(str1, "abcdef");
strcpy(str2, "ABCDEF");
ret = strcmp(str1, str2);
if(ret < 0)
{
printf("str1 is less than str2");
}
else if(ret > 0)
{
printf("str2 is less than str1");
}
else
{
printf("str1 is equal to str2");
}
return(0);
}
2.What does the following statement imply?
int arr[]={1,2,3,4,5,6,7,8,9,10};
A. Array uses only data type in its declaration
B. Array uses continuous memory addresses
C. Array is expandable
D. Array is derived data type
1. What is not true for an array?
A. The integer array does not contain any element.
B. The array contains 10 elements and the values are
natural numbers between 1 to 10.
C. The statement is not valid.
D. Array should have a dimension which is not given here.
GO TO TOPICS
4. A matrix is a
A. We may use a loop to feed values into array.
B. An array can contain values belonging to different data type
categories.
C. An array can have only one dimension
D. An array cannot be copied to another variable of fundamental
data type
3. Which of the following statements is false?
A. Single dimensional array
B. Two dimensional array
C. Three dimensional array
D. Four dimensional array
6. How many elements may be accommodated in
an array of dimension m and n? int arr[m][n]
A. Nested brackets are not allowed
B. There should not be any comma among between the numbers
C. There must be commas between the rows
D. The matrix is not having any dimensions mentioned for it.
5. What is wrong in this expression?
int mat[][]={{3,4},{7,8},{4,5},{20,10}}
A. Total number of elements that can be accommodated will
be m x n.
B. Total of m number of elements can be accommodated.
C. Total of n number of elements can be accommodated.
D. The declaration is defective
A. mat[0][0],mat[0][y],mat[x][0],mat[x][y]
B. mat[y][0],mat[0][y],mat[0][x],mat[x][y]
C. mat[0][x],mat[0][y],mat[x][0],mat[y][0]
D. mat[x][0],mat[x][y],mat[y][0],mat[y][y]
7. What are the four corner points of a matrix declared as int
mat[x][y]?
9. Which function is used for checking if a
character is a control character?
A. isletter()
B. checkalpha()
C. isalpha()
D. checkletter()
8. Which function is used for checking if a character is
alphabet?
A. isspecial()
B. iscntrl()
C. isgraphic()
D. checkspl()
11. Which function is used for checking if a character is a
punctuation?
A. isnum()
B. isnumber()
C. isdigit()
D. checkdigit()
10. Which function is used for checking if a character is a
digit?
A. ispunct()
B. ispnct()
C. isgraphic()
D. isdigit()
13. A length of the String may be calculated with
one of the following function. Identify the same.
A. Array of Characters
B. Array of Characters terminated with a ‘0’ null character
C. Is an object
D. Same as characters
12. String ar
A. strlength()
B. strlen()
C. strln()
D. length()
15. If you have to write a function for finding the length
of string. What will be the logic?
A. Joining two String
B. Merging two String
C. Cutting one string with another
D. None of the above
14. strcat() is used for
A. Read the character in an array and count them until you reach the and of the
array
B. Read the character in an array and count them until you encounter a ‘0’.
C. The dimension of the declared character is the length of the string
D. None of the Above
Continue……
In Slide 3

More Related Content

What's hot

Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
vikram mahendra
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
aarockiaabinsAPIICSE
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
Monika Sanghani
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
vikram mahendra
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
Anton Kolotaev
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
Deyvessh kumar
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Saranya saran
 

What's hot (20)

Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Advanced C - Part 3
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Arrays
ArraysArrays
Arrays
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 

Similar to VIT351 Software Development VI Unit2

Array
ArrayArray
Array
Anil Dutt
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
HimanshuKansal22
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
GOKULKANNANMMECLECTC
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
mohd_mizan
 
02 arrays
02 arrays02 arrays
02 arrays
Rajan Gautam
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Arrays
ArraysArrays
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
Arrays
ArraysArrays
Arrays
AnaraAlam
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
Muhammad Hammad Waseem
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Array
ArrayArray

Similar to VIT351 Software Development VI Unit2 (20)

Array
ArrayArray
Array
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
02 arrays
02 arrays02 arrays
02 arrays
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Arrays
ArraysArrays
Arrays
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Arrays
ArraysArrays
Arrays
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Unit3 C
Unit3 C Unit3 C
Unit3 C
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Array
ArrayArray
Array
 

More from YOGESH SINGH

VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
YOGESH SINGH
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
YOGESH SINGH
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
YOGESH SINGH
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
YOGESH SINGH
 
DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3
YOGESH SINGH
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2
YOGESH SINGH
 
DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1
YOGESH SINGH
 

More from YOGESH SINGH (8)

VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
 
DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2
 
DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1
 

Recently uploaded

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 

Recently uploaded (20)

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 

VIT351 Software Development VI Unit2

  • 1. D.E.I. TECHNICAL COLLEGE COURSE TITLE: Software Development-VI SLIDE-2 COURSE CODE: VIT351 CLASS: DIPLOMA IN INFORMATION TECHNOLOGY VOCATIONAL (1ST YEAR) SESSION: 2019-20
  • 2. TOPICS COVERED  ARRAYS IN C  MULTIDIMENSIONAL ARRAYS  CHARACTER HANDLING IN C  STRING HANDLING IN C  QUIZ SET 2
  • 3.
  • 4. What is an Array?  Arrays are the collection of a finite number of homogeneous data elements.  Elements of the array are referenced respectively by an index set consisting of n consecutive numbers and are stored respectively in successive memory locations.  The number n of elements is called the length or size of the array. GO TO TOPICS
  • 5. Continue….  Array is a collection of similar elements. These similar elements could be all ints, floats, doubles, chars, etc. Array is also known as subscript variable.  Array can store a fixed-size sequential collection of elements of the same type.  Array elements are stored in contiguous memory block.  Instead of declaring individual variables, such as number0, number1, ..., and number99, you can declare one array variable.  Creating array is creating a group of variables and all its elements are accessed via single name and different subscript values.
  • 6. Properties of an Array 1) Indexing of an array begins from zero (0). 2) The variable name of array contains the base address of the memory block. 3) The array variable are created at the time of compilation. 4) The size of the array cannot be altered at runtime.
  • 7. How to declare an Array? Syntax: dataType arrayName[arraySize]; For example, float mark[5]; This is called single dimensional array. Here, we declared an array, mark, of floating-point type. And its size is 5. Meaning, it can hold 5 floating-point values. It's important to note that the size and type of an array cannot be changed once it is declared.
  • 8.  Array declaration by specifying size // Array declaration by specifying size int arr1[10]; // With recent C/C++ versions, we can also // declare an array of user specified size int n = 10; int arr2[n];  Array declaration by initializing elements // Array declaration by initializing elements int arr[] = { 10, 20, 30, 40 } // Compiler creates an array of size 4. // above is same as "int arr[4] = {10, 20, 30, 40}"  Array declaration by specifying size and initializing elements // Array declaration by specifying size and initializing elements int arr[6] = { 10, 20, 30, 40 } // Compiler creates an array of size 6, initializes first // 4 elements as specified by user and rest two elements as 0. // above is same as "int arr[] = {10, 20, 30, 40, 0, 0}"
  • 9. How to access an Array?  Array elements are accessed by using an integer index.  Index of an array starts from 0 to size-1 i.e first element of arr array will be stored at arr[0] address. Example: #include <stdio.h> int main() { int arr[5]; arr[0] = 5; arr[2] = -10; arr[3 / 2] = 2; // this is same as arr[1] = 2 arr[3] = arr[0]; printf("%d %d %d %d", arr[0], arr[1], arr[2], arr[3]); return 0; }
  • 10. Initialization of an Array  After an array is declared it must be initialized. Otherwise, it will contain garbage value(any random value). An array can be initialized at either compile time or at runtime. data-type array-name[size] = { list of values }; /* Here are a few examples */ int marks[4]={ 67, 87, 56, 77 }; // integer array initialization float area[5]={ 23.4, 6.8, 5.5 }; // float array initialization int marks[4]={ 67, 87, 56, 77, 59 }; // Compile time error In such case, there is no requirement to define the size. So it may also be written as the following code. int marks[]={20,30,40,50,60};
  • 11. Example: #include <stdio.h> int main() { int marks[10], i, n, sum = 0, avg; printf("Enter number of elements: "); scanf("%d", &n); for(i=0; i<n; i++) { printf("Enter number"); scanf("%d", &marks[i]); // adding integers entered by the user to the sum variable sum =sum+marks[i]; } avg = sum/n; printf("Average = %d", avg); return 0; }
  • 12. Multi-dimensional Array  C language supports multidimensional arrays also.  The simplest form of a multidimensional array is the two-dimensional array.  Both the row's and column's index begins from 0. Declaration: data-type array-name[row-size][column-size] /* Example */ int a[3][4]; GO TO TOPICS
  • 13. Initialization of 2-D Array  int b[2] [3] = {12,65,78,45,33,21}; //valid  int b[ ] [3] = {12,65,78,45,33,21}; // valid  int b[2] [ ] = {12,65,78,45,33,21}; //invalid  int b[ ] [ ] = {12,65,78,45,33,21}; // invalid
  • 14. Example: Adding two matrices #include <stdio.h> int main() { int i,j; int a[2][2], b[2][2], result[2][2]; // Taking input using nested for loop printf("Enter elements of 1st matrixn"); for (i = 0; i < 2; i++) for (j = 0; j < 2; j++){ printf("Enter a%d%d: ", i + 1, j + 1); scanf("%d", &a[i][j]); } // Taking input using nested for loop printf("Enter elements of 2nd matrixn"); for (i = 0; i < 2; i++) for (j = 0; j < 2; j++){ printf("Enter b%d%d: ", i + 1, j + 1); scanf("%d", &b[i][j]); } // adding corresponding elements of two arrays for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) { result[i][j] = a[i][j] + b[i][j]; } // Displaying the sum printf("nSum Of Matrix:n"); for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) { printf("%dt", result[i][j]); if (j == 1) printf("n"); } return 0; }
  • 15. Important Note:  The array elements can be accessed in a constant time by using the index of the particular element.  To access an array element, address of an element is computed as an offset from the base address of the array and one multiplication is needed to compute what is supposed to be added to the base address to get the memory address of the element  First the size of an element of that data type is calculated and then it is multiplied with the index of the element to get the value to be added to the base address.  This process takes one multiplication and one addition. Since these two operations take constant time, we can say the array access can be performed in constant time.
  • 16.
  • 17. Dealing with Characters ctype.h file includes functions that are useful for testing and mapping characters. All the functions defined in ctype.h accept int as a parameter, whose value must be EOF or representable as an unsigned char. These functions return non-zero (true) if the argument satisfies the condition described else the functions return zero (false). GO TO TOPICS
  • 18. isalnum() Function  Description The C library function void isalnum(int c) checks if the passed character is alphanumeric.  Declaration int isalnum(int c);  Parameters c − This is the character to be checked.  Return Value This function returns non-zero value if c is a digit or a letter, else it returns 0.
  • 19. Example:1#include <ctype.h> #include<stdio.h> int main () { int var1 = 'a'; int var2 = '4'; int var3 = 't'; if( isalnum(var1) ) { printf("var1 = |%c| is alphanumericn", var1 ); } else { printf("var1 = |%c| is not alphanumericn", var1 ); } if( isalnum(var2) ) { printf("var2 = |%c| is alphanumericn", var2 ); } else { printf("var2 = |%c| is not alphanumericn", var2 ); } if( isalnum(var3) ) { printf("var3 = |%c| is alphanumericn", var3 ); } else { printf("var3 = |%c| is not alphanumericn", var3 ); } return(0); }
  • 20. isalpha() Function  Description The C library function void isalpha(int c) checks if the passed character is alphabet.  Declaration int isalpha(int c);  Parameters c − This is the character to be checked.  Return Value This function returns non-zero value if c is a letter, else it returns 0.
  • 21. Example:2#include <stdio.h> #include <ctype.h> int main () { int var1 = 'a'; int var2 = '4'; int var3 = 't'; if( isalpha(var1) ) { printf("var1 = |%c| is an alphabetn", var1 ); } else { printf("var1 = |%c| is not an alphabetn", var1 );} if( isalpha(var2) ) { printf("var2 = |%c| is an alphabetn", var2 ); } else { printf("var2 = |%c| is not an alphabetn", var2 );} if( isalpha(var3) ) { printf("var3 = |%c| is an alphabetn", var3 ); } else { printf("var3 = |%c| is not an alphabetn", var3 );} return(0); }
  • 22. iscntrl() Function  Description The C library function void iscntrl(int c) checks if the passed character is a control character.  Declaration int iscntrl(int c);  Parameters c − This is the character to be checked.  Return Value This function returns non-zero value if c is a control character, else it returns 0.
  • 23. Example:3#include <stdio.h> #include <ctype.h> int main () { int i = 0, j = 0; char str1[] = "We like to learn a about t programming"; char str2[] = "these tutorials n are nice"; /* Prints string till control character a */ while( !iscntrl(str1[i]) ) { putchar(str1[i]); i++; } /* Prints string till control character n */ while( !iscntrl(str2[j]) ) { putchar(str2[j]); j++; } return(0); }
  • 24. isdigit() Function  Description The C library function void isdigit(int c) checks if the passed character is a decimal digit character. Decimal digits are (numbers) − 0 1 2 3 4 5 6 7 8 9.  Declaration int isdigit(int c);  Parameters c − This is the character to be checked.  Return Value This function returns non-zero value if c is a digit, else it returns 0.
  • 25. ispunct() Function  Description The C library function int ispunct(int c) checks whether the passed character is a punctuation character. A punctuation character is any graphic character (as in isgraph) that is not alphanumeric (as in isalnum).  Declaration int ispunct(int c);  Parameters c − This is the character to be checked.  Return Value This function returns a non-zero value(true) if c is a punctuation character else, zero (false).
  • 26. isspace() Function  Description The C library function int isspace(int c) checks whether the passed character is white- space.Standard white-space characters are:  ' ' (0x20) space (SPC)  't' (0x09) horizontal tab (TAB)  'n' (0x0a) newline (LF)  'v' (0x0b) vertical tab (VT)  'f' (0x0c) feed (FF)  'r' (0x0d) carriage return (CR) Declaration int isspace(int c); Parameters c − This is the character to be checked. Return Value This function returns a non-zero value(true) if c is a white-space character else, zero (false).
  • 27. String Handling in C  String is a sequence of characters that is treated as a single data item and terminated by null character '0'.  Remember that C language does not support strings as a data type.  A string is actually one-dimensional array of characters in C language.  These are often used to create meaningful and readable programs.  C language supports a large number of string handling functions that can be used to carry out many of the string manipulations. These functions are packaged in string.h library. char name[12] = “DataScience"; // valid character array initialization char name[12] = {‘d',‘a',‘t',‘a',‘s',‘c',‘i',’e’,’n’,’c’,’e’,'0'}; // valid initialization char ch[3] = “data"; // Illegal char str[4]; str = “data"; // Illegal GO TO TOPICS
  • 28.  strlen() o prototype: int strlen(char *); o It calculates the length of the given string  strrev() o prototype: char* strrev(char*); o It reverses the given string  strlwr() o prototype: char* strlwr(char*); o It converts the given string into its corresponding lower case  strupr() o prototype: char* strupr(char*); o It converts the given string into its corresponding upper case  strcpy() o prototype: char* strcpy(char*, char*); o It copies the second string into first
  • 29.  strcat() o prototype: char* strcat(char*, char*); o It simply appends or concatenates the two strings.  strcmp() o prototype: int strcmp(char*, char*); o It compares two strings and return -1, 0 or 1, indicative values. Return 0 if strings are identical. Returns -1 if first string appears before the second string in the dictionary. Returns 1 if first string appears after the second string in the dictionary. OR  if Return value < 0 then it indicates str1 is less than str2.  if Return value > 0 then it indicates str2 is less than str1.  if Return value = 0 then it indicates str1 is equal to str2.
  • 30. Example:1&2#include <stdio.h> #include <string.h> int main() { char str1[12] = "Hello"; char str2[12] = "Team"; char str3[12]; int len ; /*copy str1 into str3 */ strcpy(str3, str1); printf("strcpy(str3, str1) : %sn", str3 ); /*concatenates str1 and str2 */ strcat (str1, str2); printf("strcat(str1, str2) : %sn", str1 ); /*total lenghth of str1 after concatenation */ len = strlen (str1); printf("strlen(str1) : %dn", len ); return 0; } #include <stdio.h> #include <string.h> int main () { char src[50], dest[50]; strcpy(src, "This is source"); strcpy(dest, "This is destination"); strcat(dest, src); printf("Final destination string : |%s|", dest); return(0); }
  • 31. Example:3 #include <stdio.h> #include <string.h> int main () { char str1[15]; char str2[15]; int ret; strcpy(str1, "abcdef"); strcpy(str2, "ABCDEF"); ret = strcmp(str1, str2); if(ret < 0) { printf("str1 is less than str2"); } else if(ret > 0) { printf("str2 is less than str1"); } else { printf("str1 is equal to str2"); } return(0); }
  • 32. 2.What does the following statement imply? int arr[]={1,2,3,4,5,6,7,8,9,10}; A. Array uses only data type in its declaration B. Array uses continuous memory addresses C. Array is expandable D. Array is derived data type 1. What is not true for an array? A. The integer array does not contain any element. B. The array contains 10 elements and the values are natural numbers between 1 to 10. C. The statement is not valid. D. Array should have a dimension which is not given here. GO TO TOPICS
  • 33. 4. A matrix is a A. We may use a loop to feed values into array. B. An array can contain values belonging to different data type categories. C. An array can have only one dimension D. An array cannot be copied to another variable of fundamental data type 3. Which of the following statements is false? A. Single dimensional array B. Two dimensional array C. Three dimensional array D. Four dimensional array
  • 34. 6. How many elements may be accommodated in an array of dimension m and n? int arr[m][n] A. Nested brackets are not allowed B. There should not be any comma among between the numbers C. There must be commas between the rows D. The matrix is not having any dimensions mentioned for it. 5. What is wrong in this expression? int mat[][]={{3,4},{7,8},{4,5},{20,10}} A. Total number of elements that can be accommodated will be m x n. B. Total of m number of elements can be accommodated. C. Total of n number of elements can be accommodated. D. The declaration is defective
  • 35. A. mat[0][0],mat[0][y],mat[x][0],mat[x][y] B. mat[y][0],mat[0][y],mat[0][x],mat[x][y] C. mat[0][x],mat[0][y],mat[x][0],mat[y][0] D. mat[x][0],mat[x][y],mat[y][0],mat[y][y] 7. What are the four corner points of a matrix declared as int mat[x][y]?
  • 36. 9. Which function is used for checking if a character is a control character? A. isletter() B. checkalpha() C. isalpha() D. checkletter() 8. Which function is used for checking if a character is alphabet? A. isspecial() B. iscntrl() C. isgraphic() D. checkspl()
  • 37. 11. Which function is used for checking if a character is a punctuation? A. isnum() B. isnumber() C. isdigit() D. checkdigit() 10. Which function is used for checking if a character is a digit? A. ispunct() B. ispnct() C. isgraphic() D. isdigit()
  • 38. 13. A length of the String may be calculated with one of the following function. Identify the same. A. Array of Characters B. Array of Characters terminated with a ‘0’ null character C. Is an object D. Same as characters 12. String ar A. strlength() B. strlen() C. strln() D. length()
  • 39. 15. If you have to write a function for finding the length of string. What will be the logic? A. Joining two String B. Merging two String C. Cutting one string with another D. None of the above 14. strcat() is used for A. Read the character in an array and count them until you reach the and of the array B. Read the character in an array and count them until you encounter a ‘0’. C. The dimension of the declared character is the length of the string D. None of the Above