Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

programming in c

Rating
-
Sold
-
Pages
23
Uploaded on
21-08-2023
Written in
2023/2024

Programming in C refers to the process of creating computer programs using the C programming language. C is a general-purpose, procedural programming language that was developed in the early 1970s by Dennis Ritchie at Bell Labs. It has since become one of the most widely used and influential programming languages in the history of computing. Here are some key characteristics and concepts associated with programming in C: 1. **Syntax and Structure:** C programs are written using a specific syntax and structure defined by the language. Statements and commands are structured in a way that tells the computer what actions to perform. 2. **Procedural Paradigm:** C is a procedural programming language, which means that programs are organized into functions or procedures that perform specific tasks. These functions can be called in a sequence to accomplish complex tasks. 3. **Variables and Data Types:** C allows you to declare variables to store data. Data types like integers, floating-point numbers, characters, and more are used to define the type of data a variable can hold. 4. **Control Flow:** C provides control structures such as loops (for, while, do-while) and conditional statements (if, else if, else) to control the flow of program execution based on certain conditions. 5. **Functions:** Functions are a fundamental building block in C programming. They allow you to modularize your code by breaking it into smaller, manageable pieces that can be reused throughout the program. 6. **Pointers:** Pointers are a unique feature of C that allow you to work with memory addresses directly. They are essential for tasks like dynamic memory allocation and manipulation of data structures. 7. **Memory Management:** In C, you have direct control over memory management, which can be both a powerful tool and a source of potential errors. You can allocate and deallocate memory dynamically using functions like `malloc()` and `free()`. 8. **Standard Library:** C comes with a standard library that provides a set of pre-built functions and macros to perform common tasks, such as input/output operations, string manipulation, mathematical calculations, and more. 9. **Compilation:** C programs are compiled before they can be executed. The source code is translated into machine-readable binary code by a compiler, resulting in an executable file that can be run on the target system. 10. **Portability:** C is known for its portability across different hardware architectures and operating systems. This means that a C program written on one system can often be compiled and run on another system without major modifications. 11. **Low-Level Features:** C allows you to interact closely with the hardware and perform low-level operations, making it suitable for systems programming, embedded programming, and other scenarios where fine-grained control is necessary. Programming in C can be both rewarding and challenging. While its flexibility and performance benefits make it a popular choice for various applications, its manual memory management and potential for errors require programmers to be careful and diligent in their coding practices.

Show more Read less
Institution
Course

Content preview

, EST102 Programming in C


Module V
Pointers and Files-Basics of Pointer: declaring pointers, accessing data though pointers, NULL
pointer,array access using pointers, pass by reference effect. File Operations: open, close, read,
write, append Sequential access and random access to files: In built file handling functions
(rewind() ,fseek(), ftell(),feof(), fread(), fwrite()), simple programs covering pointers and files.


POINTERS
The pointer in C language is a variable which stores the address of another variable.
This variable can be of type int, char, array, function, or any other pointer. The size of the
pointer depends on the architecture. However, in 32-bit architecture the size of a pointer is
2 byte.
Consider the following example to define a pointer which stores the address of an
integer variable.
int n = 10;
int *p = &n; // Variable p of type pointer is pointing to the address of the variable n of type
integer.
Declaration of Pointer Variable
The pointer in C language can be declared using * (asterisk symbol). It is also known
as indirection operator used to dereference a pointer.
datatype *ptrvar;
where ptrvar is any identifier
int *a; //pointer to integer
char *c; //pointer to char

Initialization of Pointer Variable
The process of assigning the address of a variable to a pointer variable is known as
initialization. All uninitialized pointers have some garbage value so it should be initialized.
Example
int a;
int *p; //declaration
p=&a; //initialization




IIPE 1


Downloaded from Ktunotes.in

, EST102 Programming in C


Accessing Data through Pointers
A variable can be accessed through its pointer using unary operator ’*’. Also known
as indirection operator or dereferencing operator.
Consider the following example:

#include<stdio.h>
void main()
{
int n = 10;
int *p;
p = &n;
printf("Address of n=%u\n",&n);
printf("Value of n=%d\n",n);
printf("Address of p=%u\n",&p);
printf("Value of p=%u\n",p);
printf("Value of *p=%d\n",*p); // *p = value of n;

}
OUTPUT
Address of n=6487628
Value of n=10
Address of p=6487616
Value of p=6487628
Value of *p=10

Each variable has two properties: address and value. Address of a variable is the
memory location allocated for that variable. Value of a variable is the value stored in the
memory location allocated to them. The address of a variable can be derived using address
of (&) operator. In the example above, the address of n is 6487628 and value is 10.


Variable Name Address Value
n 6487628 10
When p is assigned with &n, p stores the address of n. Thus p points to n. In order to
retrieve the value of n, we can make use of *p.
Pointer Name Address of p Value of p Asterisk Value(*p)
6487628 10
p 6487616
Address of variable n Value of n


IIPE 2


Downloaded from Ktunotes.in

Written for

Institution
Course

Document information

Uploaded on
August 21, 2023
Number of pages
23
Written in
2023/2024
Type
Class notes
Professor(s)
Noisytech13
Contains
All classes

Subjects

$8.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
noisytech13

Get to know the seller

Seller avatar
noisytech13 noisytech13
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
5
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions