Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Syntex:

Sure, here's a basic overview of C syntax:

1. Comments: Comments in C are preceded by // for single-line comments and enclosed between /* and */ for multi-line comments.

// This is a single-line comment /* This is a multi-line comment */

2. Data Types: C has several basic data types such as int, float, char, double, etc.

int num = 10;
float pi = 3.14;
char letter = 'A';
double bigNum = 123456789.123456789;

3. Variables: Variables must be declared before use. They are declared by specifying the data type followed by the variable name.

int x; float y;

4. Constants: Constants are declared using the const keyword

const int MAX_VALUE = 100;

5. Operators: C supports various operators including arithmetic, relational, logical, assignment, etc.

int a = 5, b = 3; int sum = a + b; int difference = a - b; int product = a * b; int quotient = a / b; int remainder = a % b; if (a > b) { // do something } int result = (a > b) ? a : b; // Ternary operator

6. Control Structures: C provides control structures like if, else, switch, while, do-while, for, etc.

if (condition) {
// code block
} else if (another_condition) {
// code block
} else {
// code block
}

switch (expression) {
case constant1:
// code block
break;
case constant2:
// code block
break;
default:
// code block
break;
}

while (condition) {
// code block
}

do {
// code block
} while (condition);

for (initialization; condition; update) {
// code block
}

7. Functions: Functions in C are declared with a return type, function name, and parameters.

int add(int a, int b) {
return a + b;
}

8. Arrays: Arrays are collections of similar data items under one name and are indexed from

int numbers[5] = {1, 2, 3, 4, 5};

9. Pointers: Pointers are variables that store the memory address of another variable.

int *ptr; int num = 10; ptr = # // ptr now holds the address of num

10. Structures and Unions: Structures allow you to group variables of different types under one name.

struct Point { int x; int y; }; struct Point p1; p1.x = 10; p1.y = 20;

11. Dynamic Memory Allocation: C provides functions like malloc(), calloc(), realloc(), and free() for dynamic memory allocation.

int *ptr; ptr = (int *)malloc(5 * sizeof(int)); // Allocating memory for 5 integers

These are the basics of C syntax. C is a powerful language with a relatively simple syntax compared to some modern languages, making it suitable for systems programming and other applications where performance and control are critical.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java