0% found this document useful (0 votes)
3 views3 pages

C Programming: Loops, Functions, Arrays

The document covers fundamental concepts in C programming, including loops, functions, arrays, and strings. It explains the types of loops (while, do-while, for), the structure and purpose of functions, and the use of arrays and strings for data storage and manipulation. Examples are provided to illustrate each concept, highlighting their importance in writing efficient and modular code.

Uploaded by

poojithalagu5684
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)
3 views3 pages

C Programming: Loops, Functions, Arrays

The document covers fundamental concepts in C programming, including loops, functions, arrays, and strings. It explains the types of loops (while, do-while, for), the structure and purpose of functions, and the use of arrays and strings for data storage and manipulation. Examples are provided to illustrate each concept, highlighting their importance in writing efficient and modular code.

Uploaded by

poojithalagu5684
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

1.

Loops in C Programming Loops allow repeated execution


of a block of code until a condition is met. They are
fundamental in writing efficient programs. Types of Loops:
While Loop: Checks condition first, executes only if true.
Do-While Loop: Executes once before checking condition.
For Loop: Best for known number of iterations. Example of
While Loop: #include <stdio.h> int main() { int i = 1; while (i
<= 10) { printf("%d\n", i); i++; } return 0; } This prints numbers
from 1 to 10. Notice that the loop continues until i <= 10
becomes false. Loops are also used for traversing arrays,
reading input repeatedly, and building patterns.
2. Functions in C Functions divide programs into smaller,
reusable modules. They make programs easier to
understand, test, and maintain. Why Functions? Code
reusability Improved readability Modularity for large programs
Structure of a Function: returnType
functionName(parameters) { // body } Example: #include
<stdio.h> int square(int n) { return n * n; } int main() {
printf("Square of 6 = %d", square(6)); return 0; } Functions can
be library functions like printf(), or user-defined. They may
also use recursion, where a function calls itself.
3. Arrays and Strings Arrays are collections of similar data
items stored at contiguous memory locations. Strings are
arrays of characters. Example: Array #include <stdio.h> int
main() { int arr[5] = {10, 20, 30, 40, 50}; for (int i = 0; i < 5; i++)
{ printf("%d ", arr[i]); } return 0; } Two-Dimensional Arrays:
Used to represent matrices or tables. Strings: #include
<stdio.h> #include <string.h> int main() { char str[20] =
"Hello"; printf("Length = %lu", strlen(str)); return 0; } Common
string functions are strlen, strcpy, strcmp, and strcat.
Arrays and strings are heavily used in data storage, input
handling, and algorithms.

You might also like