0% found this document useful (0 votes)
21 views

C langauage notes

Uploaded by

joshvongy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

C langauage notes

Uploaded by

joshvongy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

What is C language ?

C is a general-purpose programming language that was originally developed in


the early 1970s by Dennis Ritchie at Bell Labs. It is a structured, high-level
programming language that allows programmers to write efficient, portable, and
maintainable code.

C has become a popular language for systems programming, operating systems,


embedded systems, and other low-level programming tasks, due to its ability to
interface with hardware and its low-level memory management features. C is
also widely used in application programming, such as in the development of
software for desktop applications, games, and mobile devices.

C has influenced many other programming languages, including C++, Java, and
Python. It is often taught as a first programming language in universities and is
still widely used today.

What is compiler ?

A compiler is a software tool that translates source code written in a


programming language into machine code that a computer can understand and
execute. The compiler takes the source code as input and produces an
executable program as output.

The process of compiling involves several stages, including lexical analysis,


syntax analysis, semantic analysis, code generation, and optimization. In the
lexical analysis stage, the compiler breaks the source code into tokens, such as
keywords, identifiers, and operators. In the syntax analysis stage, the compiler
checks the tokens against the rules of the programming language's grammar to
ensure that they form a valid program. In the semantic analysis stage, the
compiler checks the program's semantics to ensure that it is well-formed and
meaningful. In the code generation stage, the compiler produces machine code
that can be executed by a computer. In the optimization stage, the compiler tries
to improve the efficiency and speed of the resulting machine code.

Compilers are essential tools for software development and are used in many
different fields, including application development, system programming, and
embedded systems. Some popular compilers include GCC (GNU Compiler
Collection), Clang, and Microsoft Visual C++.
Difference interpreter and compiler?

Both interpreters and compilers are software tools that translate code written in
a high-level programming language into machine code that can be executed by a
computer. However, there are some fundamental differences between the two:

 Interpreter: An interpreter is a program that directly executes source code


line by line without first converting it into machine code. The interpreter
reads each line of the source code, translates it into machine code, and
executes it immediately. This means that the code can be run without the
need for a separate compilation step. However, since the interpretation is
done on a line-by-line basis, interpreters can be slower than compilers for
large programs. Examples of interpreted languages include Python, Ruby,
and JavaScript.
 Compiler: A compiler is a program that converts the entire source code
into machine code all at once, producing an executable program that can
be run directly on the computer. The compiler analyzes the entire code
base, optimizes it, and generates machine code that can be executed by
the computer. This results in faster execution times compared to
interpreted languages, but requires an additional compilation step before
the code can be run. Examples of compiled languages include C, C++, and
Java.

In summary, interpreters execute code line by line, while compilers convert the
entire code base into machine code all at once. Interpreted languages are
generally easier to write and debug, but can be slower, while compiled
languages are generally faster, but require a separate compilation step.

Definition of header file?

A header file is a file in C and C++ programming languages that contains


declarations for functions, variables, and other constructs that are used in a
program. The header file typically has a file extension of .h and is included in the
program using the #include directive.

Header files are used to modularize code and simplify programming. By


declaring functions and variables in a header file, they can be shared and reused
across multiple source code files. This can save time and effort, as it reduces the
need to redeclare the same functions and variables in each source code file.

Common examples of header files in C and C++ include stdio.h, which contains
declarations for standard input and output functions, and math.h, which contains
declarations for mathematical functions. Header files can be created by
programmers and shared with others to simplify the process of writing programs.

NOTES GIVEN by anand sir

The origin of C is closely tied to the development of the "Unix operating system",

originally implemented in assembly language on a PDP-7 by "Dennis Ritchie" and 'Ken Thompson’,

incorporating several ideas from colleagues

Eventually, they decided to port the 0S to a 'PDP-11'.

The original PDP-11 version of Unix was also developed in "assembly language".

Thompson wanted a programming language for developing utilities for the new platform.

At first, he tried to write a Fortran compiler, but soon gave up the idea.

Instead, he created a cut-down version of the recently developed BCPL systems programming
language

The official description of BCPL was not available at the time and Thompson modified the syntax to
be less wordy, and similar to a simplified "ALGOL" known as "SMALGOL". Thompson called the
result B. He described B as "BCPL semantics with a lot of SMALGOL syntax". Like BCPL, B had a
'Bootstrapping. Compiler to Facilitate Porting’ to new machines. However, few utilities were
ultimately written in B because it was too slow, and could not take advantage of PDP-11 features
such as 'byte addressability'.

Language that computer understands is called low level language

Language that humans understand is called high level language

Preproccer commond is

Processer and preproccer (find the didderent )

What is GNU?

Question 1: What is an array? Explain it in detail.

Definition:

An array is a collection of elements or values of the same data type stored in a contiguous block of
memory. Each element in an array is identified by its index or position in the array, which starts at 0.

Description:

Arrays are used to store a group of related variables of the same data type. Instead of declaring
individual variables, you can declare an array to store them all. This makes it easier to access and
manipulate large sets of data in your program. In C, arrays are of fixed size and the size of the array
needs to be specified at the time of declaration.

Example:

int numbers[5]; // declare an integer array of size 5

float grades[10]; // declare a float array of size 10

char name[20]; // declare a character array of size 20

double prices[100]; // declare a double array of size 100

Explanation:

In the example above, we have declared four different arrays of different data types and sizes. The
first array, numbers, is an array of integers and has a size of 5. This means it can hold 5 integer
values. The second array, grades, is an array of floating-point numbers and has a size of 10. The third
array, name, is an array of characters and has a size of 20. The fourth array, prices, is an array of
double-precision floating-point numbers and has a size of 100.

Question 2: What is a pointer? Explain it in detail.

Definition:

A pointer is a variable that stores the memory address of another variable. In C, pointers are used to
access and manipulate memory directly. They are also used for dynamic memory allocation and
deallocation.

Description:

Pointers are one of the most powerful features of the C language. They allow you to create flexible
and efficient programs that can access and manipulate memory directly. In C, every variable has a
memory address, which is the location of the variable in memory. A pointer variable stores this
memory address and allows you to access the value of the variable indirectly.

Example:

int x = 10; // declare an integer variable x and initialize it to 10

int *p; // declare a pointer variable p that points to an integer

p = &x; // assign the address of x to p

Explanation:

In the example above, we first declare an integer variable x and initialize it to 10. We then declare a
pointer variable p that can store the memory address of an integer. We assign the address of x to p
using the address-of operator (&). Now p points to x and we can access the value of x indirectly
through p. For example, we can print the value of x using the following statement:

printf("%d\n", *p);

This statement dereferences the pointer p using the dereference operator (*) and prints the value of
the integer variable x.

Question 3: What is the structure of an array?


The structure of an array is a contiguous block of memory that stores a collection of elements of the
same data type. Each element in an array is identified by its index or position in the array, which
starts at 0. The size of the array is determined at the time of declaration and cannot be changed
during runtime.

Question 4: What are the types of arrays? Explain with an example.

There are two types of arrays in C:

1. One-dimensional arrays:

A one-dimensional array is a collection of elements of the same data type stored in a contiguous
block of memory. Each element in the array is identified by its index or position in the array, which
starts at 0.

Example:

int numbers[5]; // declare

in c language answer the following question What is array ? explain it in


detail What is pointer ? explain it in detail Structure of array? types of
array ? explain with example. for first 4 que. write a detail definition ,
description, 4 example and explain any 1 example in description

You might also like