C-programming Bachelor in Civil engineering

0

   


Introduction to c programming : 
C is a general-purpose, high-level programming language that was first developed in 1972 by Dennis Ritchie. It is a procedural language, which means that it follows a step-by-step approach to problem solving. C is widely used for system programming, embedded systems, and for developing applications for various platforms including Windows, UNIX, and Linux. It is also commonly used to write low-level system software such as device drivers, operating systems, and firmware. C is considered to be a relatively low-level language, and is often used as an intermediate language for other languages such as C++, C#, and Java. C-Characters Set
In computer programming, a character set is a collection of characters that are used in a specific writing system or language. The C programming language uses the ASCII character set, which includes 128 characters, including letters, digits, punctuation marks, and control characters. The ASCII character set includes upper-case and lower-case letters, numbers, and various special characters such as punctuation marks and control characters. It is also possible to use other character sets such as UTF-8 in C programming, which supports a much larger number of characters including those from other languages and symbols.
Keyword and Identifier in C In the C programming language, keywords are predefined words that have a specific meaning and cannot be used as variable names or function names. Examples of keywords in C include "int", "char", "while", "if", "else", "for", "return", and "void".

An identifier, on the other hand, is a name given to a variable, function, or any other user-defined item. Identifiers are used to identify these items in the program and must follow certain rules. In C, an identifier must start with a letter or underscore and can contain letters, digits, and underscores. They are case sensitive, which means that "counter" and "Counter" are considered as different identifiers.

It's worth noting that C99 standard also introduced a new set of keywords such as "_Bool", "_Complex" and "_Imaginary"

Data Types in C language

The C programming language, data types refer to the type of data that a variable can hold. The standard data types in C include:

int: used to store integers (whole numbers)float: used to store floating-point numbers (numbers with decimal points)double: used to store double-precision floating-point numbers (larger and more precise than floats)char: used to store characters (letters, digits, and special characters)void: used to represent the absence of a value or a type_Bool: introduced in C99, used to store Boolean values (true or false)_Complex and _Imaginary : introduced in C99, used to store complex and imaginary numbers respectively.

In addition to these standard data types, C also allows the creation of user-defined data types using the typedef keyword or struct, union, and enum. It's also worth noting that C99 standard introduced "long long" and "long double" to represent the larger size of int and double respectively.

Constant and Variable Decleration in C : In C, constants and variables are declared using the keyword "const" and without keyword respectively.

A constant is a value that cannot be changed during the execution of the program. Constants are declared using the keyword "const" followed by the data type and the name of the constant. The value of a constant must be assigned at the time of declaration and cannot be changed later on.

For example:

const int MAX_LIMIT = 100; const float PI = 3.14;

A variable, on the other hand, is a value that can be changed during the execution of the program. Variables are declared by specifying the data type followed by the name of the variable. The value of a variable can be changed later on.

For example:

int age; float salary;

It is also possible to initialize a variable when it is declared, by assigning a value to it at the time of declaration.

int age = 25; float salary = 50000;

It is considered a good practice to initialize the variable at the time of declaration

Format input and output in C In C, formatted input and output functions are used to read and write data from and to a stream, respectively, in a specific format. The two most commonly used formatted input/output functions are printf() and scanf().

  1. printf(): This function is used to print data to the standard output stream (typically the console). It takes a format string and a list of arguments, and prints them to the output stream according to the specified format. For example:
printf("Hello, World!\n"); int age = 25; printf("My age is %d\n", age);
  1. scanf(): This function is used to read data from the standard input stream (typically the keyboard). It takes a format string and a list of addresses of variables, and reads data from the input stream according to the specified format. For example:
int age; printf("Enter your age: "); scanf("%d", &age);

Additionally, C also have other formatted input/output functions like fprintf(), fscanf(), sprintf(), sscanf(), etc. These are used to read and write data from and to a file or a string respectively.

It's worth noting that these functions are not type safe, and if the format string doesn't match the type of the variables passed to it, it may lead to undefined behavior. C-operator


Post a Comment

0Comments
Post a Comment (0)