C langauage notes
C langauage notes
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 ?
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:
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.
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.
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’,
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'.
Preproccer commond is
What is GNU?
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:
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.
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:
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.
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: