PDF Google Drive Downloader v1.1


Báo lỗi sự cố

Nội dung text Arrays-and-Strings - Notes.pdf

Unit-5 Arrays & Strings Student-Notes By Prof. Amrutha P. V. Assistant-Professor School of Computer Information Technology REVA University Bangalore
Page | 1 Unit-5 Arrays & Strings Syllabus 1) Arrays & Strings 2) One-dimensional arrays 3) Multidimensional arrays 4) Array initialization and manipulation 5) Strings and string-functions 6) Array of strings 7) matrix operations using 2-dimensional arrays.
Page | 2 Unit-5 Arrays & Strings 1. Introduction to Arrays • An array is a collection of variables of the same type, referred to by a common name. • Elements within an array are accessed by their index. In C, arrays store data in contiguous memory locations, with the lowest address assigned to the first element and the highest to the last. • Arrays can be single-dimensional or multi-dimensional, with strings being a common type of array consisting of characters ending with a null character ('\0'). 2. Relationship Between Arrays and Pointers • Arrays and pointers are closely related. Understanding one often involves knowledge of the other. • This chapter focuses on arrays, while Chapter 5 delves deeper into pointers. 3. Declaring Single-Dimension Arrays • The general syntax for declaring a single-dimensional array is: type array_name[size]; Example: double balance[100]; This declares an array named balance that can hold 100 double values. In C89, the size of the array must be specified using a constant expression. The size is fixed during compile time. C99 allows for variable-length arrays, where sizes can be determined at runtime. These are discussed later in the text. 4. Accessing Array Elements Elements in an array are accessed using their index, which starts from 0. Syntax for accessing elements: array_name[index]; Example: balance[3] = 12.23;
Page | 3 Unit-5 Arrays & Strings • This assigns 12.23 to the fourth element (index 3) of the balance array. 5. Array Indexing • Arrays in C are zero-indexed, meaning the first element has an index of 0. • Example Declaration: char p[10]; • This creates a character array p with 10 elements, ranging from p[0] to p[9]. 6. Example Program: Integer Array Initialization • The following code demonstrates how to declare and use an integer array: Arrays are a fundamental part of C programming, enabling the storage and manipulation of multiple variables under a single name. Understanding how to declare, access, and manipulate arrays is crucial for managing data efficiently. Arrays can be used in numerous applications, from storing simple lists to handling complex data structures like matrices and strings. Example Program to Use an Array • The following program demonstrates how to declare, fill, and display an array #include int main(void) { int x[100]; /* This declares a 100-integer array */ int t; // Further operations can be added here return 0; }

Tài liệu liên quan

x
Báo cáo lỗi download
Nội dung báo cáo



Chất lượng file Download bị lỗi:
Họ tên:
Email:
Bình luận
Trong quá trình tải gặp lỗi, sự cố,.. hoặc có thắc mắc gì vui lòng để lại bình luận dưới đây. Xin cảm ơn.