what is c?

C is a programming language that is widely used for software and application development, system programming, game development, web development and more. 

  • The C language was created by Dennis M. Ritchie, at Bell Telephone Laboratories in 1972.
  •  It is an flexible language initially designed for programming the UNIX operating system. 
  • C has gained popularity. 
  • Is considered one of the most commonly utilized programming languages. 

Its simplicity and efficiency make it an excellent starting point for anyone looking to learn programming and establish a foundation, in the field.


C is a programming language that was created by Dennis Ritchie in 1972 at Bell Laboratories, 

The C language possesses characteristics;


1. General Purpose and Portable; C is a programming language that can be used for purposes and can run on platforms.


2. Low level Memory Access; C allows programmers to have control, over memory, enabling memory management.


3. Speed; Programs written in C tend to execute due to the languages efficient design.


4. Clean Syntax; C has an organized syntax making it easy for developers to write and understand code.


These features make the C language well suited for tasks such as developing operating systems or compilers.


When it comes to writing your program in C consider the example code;


c

#include <stdio.h>


int main() {

 int a = 10;

 printf("%d" a);

 return 0; 

}


Output; 10

```


Now lets explore some of the most significant features of the C language;


1. Procedural Language; C follows a programming paradigm allowing developers to structure their programs using functions and procedures.


2. Fast and Efficient; Due to its low level nature programs written in C are known for their speed and efficiency.


3. Modularity; The modular approach in C promotes code organization into modules or functions enhancing maintainability and reusability.


4. Typed; In C variables need declarations with their data types before they can be used ensuring stricter type checking during compilation.


5. General Purpose Language; The versatility of the C language allows it to be applied across domains and problem solving scenarios.


6. Set of built in Operators; With numerous operators available within its syntax programmers have flexibility when performing operations on data in their programs.


7. Libraries with Rich Functions; The vast collection of libraries provides functionality that developers can utilize in their applications without reinventing the wheel.


8. Middle Level Language; C strikes a balance between level and low level languages allowing programmers to achieve both abstraction and control.


9. Portability; C programs can be compiled to run on platforms with modifications making them highly portable.


10. Easy to Extend; The C language supports integration with programming languages enabling developers to extend their programs capabilities through interlanguage communication.


These features collectively contribute to the enduring popularity and usefulness of the C language, in software development domains.


C program to Print “howdy international”

the following C application displays “hi there world” inside the output.


C


// simple C software to display "good day world"

 

// Header record for input output features

#include<stdio.h>

// foremost feature -

// in which the execution of program begins

int major()

{

 

    // prints hello international

    printf("whats up international");

 

    go back zero;

}

Output

howdy global



comment in C

In C there are two varieties of comments in c programming language:


single-line comment

Multi-line comment


1. singleline comment in C

singleline comment in C starts with ( // ) double ahead lower. It extends till the stop of the line and we don’t want to specify its quit.


Multi-line comment in C

The Multi-line comment in C begins with a ahead curb and asterisk ( /* ) and ends with an asterisk and ahead decrease ( */ ). Any text among /* and */ is handled as a remark and is neglected by way of the compiler.



Variables and Constants in C:


def: A variable is a named of location in memory  that stores a value. the value can be changed the during program execution.

Example:

C

int score; // Declares an integer variable named score

score = 10; // Assigns the value 10 to the variable score

score = 25; // Changes the value of score to 25



C Data Types


Data types in C specify the type of data a variable can hold. Choosing the correct data type is essential for writing efficient and accurate code. Here's an overview of different data

 types in C:


1. Basic Data Types:


Integer types: Represent whole numbers without decimal points. Examples include int (short for integer), short int, long int, and long long int. Each type has different size and range limitations.

Floating-point types: Represent decimal numbers. Examples include float and double. float offers less precision but is faster than double.

Character type: Represents single characters. Defined by the char type.

Void type: A special type that indicates the absence of a value. Useful for functions that don't return any value.

2. Derived Data Types:


Pointer types: Represent the memory address of another variable. Useful for managing memory and accessing data indirectly.

Array types: Represent a fixed-size collection of elements of the same data type. For example, int numbers[10]; declares an array of 10 integers.

Structure types: Represent a collection of variables of different data types grouped under a single name. Useful for organizing related data.

Union types: Similar to structures, but they share the same memory location for all its members. Useful when only one member needs to be accessed at a time.

Enumerated types: Define a set of named constants. Useful for creating custom data types with predefined values.

Function types: Specify the return type and parameter types of a function.


3. Modifiers:


Signed/unsigned: For integer types, signed allows negative values, while unsigned only allows positive values and zero.

Short/long: Modifies the size and range of integer types.

Const: Makes a variable constant, meaning its value cannot be changed after initialization.


Example : 


int age = 25; // Integer variable

float pi = 3.14159; // Floating-point variable

char character = 'A'; // Character variable

int numbers[5]; // Array of 5 integers


struct Point {

  int x;

  int y;

}; // Structure type



int sum(int a, int b) {

  return a + b;

}



C Input/Output with printf and scanf


1. printf:

printf is a built-in function in C used for formatted output.

It takes a format string as its first argument, followed by a variable number of arguments to be printed.

The format string specifies how the arguments should be formatted and displayed.

It uses placeholders like %d, %f, %c, and %s to represent different data types.


Example:


C

#include <stdio.h>


int main() {

  int age = 25;

  char name[] = "John";


printf("i am %s and iam %d year old" ,name , age);

  return 0;

}


2. scanf:

scanf is another built-in function used for formatted input.

It takes a format string as its first argument, followed by a variable number of memory addresses where the scanned values will be stored.

Similar to printf, the format string specifies how the input should be interpreted


#include <stdio.h>


int main() {

  int age;

  char name[20];


  printf("Enter your name: ");

  scanf("%s", name); // Reads a string into the name array


  printf("Enter your age: ");

  scanf("%d", &age); // Reads an integer into the age variable


  printf("Hello, %s! You are %d years old.\n", name, age);


  return 0;

}


Important points to remember:


Always include the stdio.h header file to use printf and scanf.

Match the format specifiers in the format string with the data types of the arguments or destination variables.

Use the & operator before variable names when using scanf to pass the memory address.

Be careful with user input as it can be unpredictable. Always validate user input to prevent errors.

Both printf and scanf return the number of arguments successfully formatted or scanned.



Operators in C

Operators are symbols used to perform operations on variables and constants in C. They play a crucial role in manipulating data and controlling program flow. Here's an overview of different types of operators in C:


1. Arithmetic Operators:


Used for performing mathematical calculations like addition, subtraction, multiplication, division, modulus, and increment/decrement.

Examples: +, -, *, /, %, ++, --

2. Comparison Operators:


Used for comparing operands and returning true or false based on the chosen condition.

Examples: ==, !=, <, >, <=, >=

3. Logical Operators:


Used to combine multiple conditions using AND, OR, and NOT operators.

Examples: &&, ||, !

4. Bitwise Operators:


Used to perform operations on individual bits of data.

Examples: &, |, ~, ^, <<, >>

5. Assignment Operators:


used to store to a variable

Examples: =, +=, -=, *=, /=, %=

6. Miscellaneous Operators:


Sizof Operator.

The sizeof operator is a powerful tool in C used to determine the size of a data type or variable in bytes. 



types of Tokens in C

The tokens of c language may be classified into six sorts based totally on the capabilities they're used to perform. The forms of C tokens are as follows:

  • key phrases
  • Identifiers
  • Constants
  • Strings
  • special Symbols
  • Operators


Token In C


     double      int        struct

wreck        else        lengthy       switch

case         enum        sign in   typedef

char         extern      go back     union

const        drift       quick      unsigned

keep     for         signed     void

default      goto        sizeof     unstable

do           if          static     while


KeyWords.------

automobile

break

case

char

const

preserve

default

do

double

else

enum

extern

glide

for

goto

if

int

long

sign up

return

short

signed

sizeof

static

struct

switch

typedef

union

unsigned

void

unstable

while

car

auto is the default storage class variable this is declared inner a function or a block.


No comments: