C Articles

Page 90 of 96

How to write long strings in Multi-lines C/C++?

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 15K+ Views

To write long strings in multi-lines, you can use the 'newline character' or 'string concatenation'. It increases the readability of the code, makes the code look clean, and you can avoid horizontal scrolling. In this article, we have a long string and our task is to write the long string in multi-lines in C. Syntax // Using newline character char str[] = "First lineSecond lineThird line"; // Using string concatenation char str[] = "First part of string " "Second part of string ...

Read More

Data Types we cannot use to create array in C

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 433 Views

In C programming, arrays can be created using most data types like int, char, float, double, etc. However, there are certain data types that cannot be used to create arrays. The most notable restriction is with the void data type. Syntax datatype array_name[size]; // Valid for most data types void array_name[size]; // Invalid - compilation error Data Types That Cannot Be Used for Arrays 1. Void Data Type The void data type represents "no type" and has no size. Since arrays need to know the size of ...

Read More

Difference between PHP and C

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 2K+ Views

PHP and C are two distinct programming languages that serve different purposes. PHP is a server−side scripting language primarily used for web development, while C is a low−level procedural programming language used for system programming. Understanding their differences helps developers choose the right tool for their projects. What is PHP? PHP (Hypertext Preprocessor) is a general−purpose programming language developed by Rasmus Lerdorf in 1994. It is primarily utilized for web development and runs on web servers to generate dynamic content. PHP code is processed by a PHP interpreter installed on web servers as a module, daemon, ...

Read More

How to pass a 2D array as a parameter in C?

George John
George John
Updated on 15-Mar-2026 1K+ Views

In C programming, a 2D array can be passed as a parameter to a function in several ways. The method depends on whether the array dimensions are known at compile time or need to be determined at runtime. Syntax // Method 1: Fixed dimensions (known at compile time) void function_name(int arr[ROWS][COLS]); // Method 2: Variable dimensions (C99 and later) void function_name(int rows, int cols, int arr[rows][cols]); // Method 3: Using pointer to array void function_name(int (*arr)[COLS]); Method 1: Using Fixed Dimensions When array dimensions are known at compile time, you can specify ...

Read More

When do function-level static variables get initialized in C/C++?

George John
George John
Updated on 15-Mar-2026 967 Views

Static variables can be defined using the static keyword. They are variables that remain in memory while the program is running, meaning their lifetime is the entire program execution. This is different from automatic variables, which remain in memory only when their function is running and are destroyed when the function exits. Function-level static variables are initialized only once − the first time the function is called. The memory for them is allocated at program load time, but the initialization occurs during the first function execution. Syntax static data_type variable_name = initial_value; Example: Static ...

Read More

Why C/C++ variables doesn’t start with numbers

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 2K+ Views

In C/C++, a variable name can have alphabets, numbers, and the underscore( _ ) character. There are some keywords in the C/C++ language. Apart from them, everything is treated as an identifier. Identifiers are the names of variables, constants, functions, etc. Syntax Valid identifier naming rules in C − // Valid identifier patterns: [a-zA-Z_][a-zA-Z0-9_]* // Valid examples: variable_name, _count, num1, my_var // Invalid examples: 1variable, 2name, 3_count Why Variables in C/C++ Can't Start with Numbers? In C and C++, variable names (also known as identifiers) cannot start with a digit due to ...

Read More

Declare variable as constant in C

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 20K+ Views

In C programming, variables can be declared as constants using the const keyword or the #define preprocessor directive. Constants ensure that variable values cannot be modified after initialization, providing data integrity and preventing accidental changes. Syntax const datatype variable_name = value; #define CONSTANT_NAME value Method 1: Using const Keyword Variables can be declared as constants by using the const keyword before the datatype of the variable. The constant variables can be initialized once only. The default value of uninitialized constant variables is zero. #include int main() { ...

Read More

Initialization of global and static variables in C

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 5K+ Views

In C language both the global and static variables must be initialized with constant values. This is because the values of these variables must be known at compile time before the program execution starts. An error will be generated if the constant values are not provided for global and static variables. Syntax // Global variable initialization data_type variable_name = constant_value; // Static variable initialization static data_type variable_name = constant_value; Example 1: Valid Initialization with Constants This example demonstrates the correct way to initialize global and static variables using constant values − ...

Read More

How do I find the length of an array in C/C++?

George John
George John
Updated on 15-Mar-2026 22K+ Views

To find the length of an array in C, we can use various approaches that are essential for array manipulation. Finding the length of an array is a fundamental task used in looping through arrays, sorting, searching, and memory management operations. In this article, we will explore different methods to determine the size of an array in C programming. Syntax // Method 1: Using sizeof operator int length = sizeof(array) / sizeof(array[0]); // Method 2: Using pointer arithmetic int length = *(&array + 1) - array; Method 1: Using sizeof() Operator The ...

Read More

When to use references vs. pointers in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 604 Views

In C programming, we work with pointers to access memory addresses and manipulate data indirectly. C does not have reference variables like C++, but understanding the difference helps when transitioning between languages. Syntax // Pointer declaration and usage datatype *pointer_name; pointer_name = &variable_name; Pointers in C Pointers are variables that store memory addresses of other variables. They provide indirect access to data and enable dynamic memory allocation. Example: Basic Pointer Usage #include int main() { int a = 8; int *ptr; ...

Read More
Showing 891–900 of 953 articles
« Prev 1 88 89 90 91 92 96 Next »
Advertisements