0% found this document useful (0 votes)
6 views2 pages

C Language Class 04

The document discusses arrays and strings in C, including how arrays store elements of the same type in contiguous memory and strings are represented as character arrays. It also provides an overview of basic file handling in C like opening, reading, writing and closing files using file pointers and functions like fopen(), fscanf(), fprintf() and fclose().

Uploaded by

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

C Language Class 04

The document discusses arrays and strings in C, including how arrays store elements of the same type in contiguous memory and strings are represented as character arrays. It also provides an overview of basic file handling in C like opening, reading, writing and closing files using file pointers and functions like fopen(), fscanf(), fprintf() and fclose().

Uploaded by

Laiba Sohail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

6) Arrays and Strings in C:

- Arrays: Arrays are a collection of elements of the same data type stored in
contiguous memory locations. In C, arrays are declared with a fixed size and can
store elements of any data type. They provide a convenient way to store and
access multiple values of the same type under a single name.
- Strings: In C, strings are represented as arrays of characters terminated by a
null character '\0'. C does not have a built-in string data type like other
programming languages. Instead, strings are represented as character arrays.
- Syntax:
- Array Declaration: `datatype array_name[size];`
- String Declaration: `char string_name[size];` char a[6]; a[0] =C, a[1]= a,
a[2]=n, a[3]=a, a[4]=d, a[5]=a

7) File Handling in C (Basic Overview):


- File handling in C involves operations such as creating, opening, reading,
writing, and closing files. Files in C are handled using pointers to structures that
represent file streams.
- Basic operations:
- Opening a file: `fopen()`
- Reading from a file: `fscanf()`, `fgets()`, etc.
- Writing to a file: `fprintf()`, `fputs()`, etc.
- Closing a file: `fclose()`
- Syntax:
- Opening a file: `FILE *fptr = fopen("filename", "mode");`
- Reading from a file: `fscanf(fptr, format_specifiers, &variables);`
- Writing to a file: `fprintf(fptr, format_specifiers, variables);`
- Closing a file: `fclose(fptr);`

You might also like