Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C Articles
Page 85 of 96
What does the operation c=a+++b mean in C/C++?
In C, the expression c = a+++b is parsed by the compiler using the "maximal munch" rule, which means it reads the longest possible token sequence. This expression is interpreted as c = (a++) + b, where a++ is the post-increment operator applied to variable a. Syntax c = a++ + b; // Post-increment a, then add b c = a + ++b; // Pre-increment b, then add to a The key difference lies in operator precedence and associativity. The post-increment operator (++) has higher precedence than the addition ...
Read More_Noreturn function specifier in C
The _Noreturn function specifier in C indicates to the compiler that a function will never return control to its caller. Functions marked with _Noreturn either terminate the program (using exit()) or run indefinitely (infinite loops). This helps the compiler optimize code and detect unreachable statements. Syntax _Noreturn return_type function_name(parameters) { /* Function body that never returns */ } Example 1: _Noreturn with exit() Function When a function marked with _Noreturn calls exit(), it terminates the program without returning control to the caller − #include #include ...
Read MoreWhat happens when a function is called before its declaration in C?
In C programming, when a function is called before its declaration, the compiler makes an assumption about the function's return type. If no prototype is provided, the compiler assumes the function returns an int by default. This can lead to compilation errors if the actual function returns a different type. Syntax return_type function_name(parameters); // Function declaration/prototype Example 1: Error with Non-Integer Return Type When a function returns a type other than int but is called before declaration, it causes a type conflict − #include int main() { ...
Read MoreWhat is evaluation order of function parameters in C?
In C programming, when we pass arguments to a function, a common question arises: what is the order of evaluation of function parameters? Is it left to right, or right to left? The C standard does not specify the evaluation order, making it implementation-defined behavior. Syntax function_name(arg1, arg2, arg3, ...); Example: Testing Parameter Evaluation Order Let's examine a program that demonstrates the evaluation order by using side effects − #include void test_function(int x, int y, int z) { printf("The value of x: %d", x); ...
Read MoreHow to Count Variable Numbers of Arguments in C?
In C programming, the ellipsis (...) allows functions to accept a variable number of arguments. To count these arguments, C provides three common approaches − passing the count as the first parameter, using NULL as a sentinel value, or parsing format specifiers like printf() does. Syntax #include return_type function_name(fixed_params, ...); va_list ap; va_start(ap, last_fixed_param); type value = va_arg(ap, type); va_end(ap); Method 1: Using Count Parameter The most straightforward approach is to pass the number of arguments as the first parameter − #include #include int get_sum(int count, ...) ...
Read MoreFunctions that are executed before and after main() in C
Here we will see how to write a code where two functions are present, and one function will be executed before the main function, and another function will be executed after the main function. These features are used to do some startup task before executing the main, and some cleanup task after executing main. To do this task we have to put attribute for these two functions. When the attribute is constructor attribute, then it will be executed before main(), and when the attribute is destructor type, then it will be executed after main(). Syntax void ...
Read MoreCreating multiple process using fork() in C
In this section we will see how to use the fork() system call to create child processes in C. The fork() function creates a new process by duplicating the calling process, allowing both parent and child processes to execute different tasks. When fork() is called, it returns different values to distinguish between processes: a positive value (child's PID) to the parent process, 0 to the child process, and -1 if the fork failed. Syntax #include pid_t fork(void); Note: This program requires a Unix-like operating system (Linux, macOS) to compile and run. The ...
Read MoreGet and Set the stack size of thread attribute in C
To get and set the stack size of thread attribute in C, we use the pthread_attr_getstacksize() and pthread_attr_setstacksize() functions. These functions allow us to query and modify the minimum stack size allocated to a thread's stack. Syntax int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); pthread_attr_getstacksize() This function retrieves the current stack size from a thread attribute object. It returns 0 on success, otherwise returns an error number. Parameters: attr − Pointer to the thread attribute object stacksize − Pointer to store the retrieved stack size in bytes ...
Read MoreOctal literals in C
In C, we can use octal literals by typing a zero before the actual number. For example, if an octal number is 25, then we have to write 025. Octal literals use base-8 numbering system and contain only digits 0-7. Syntax 0octal_digits Where octal_digits are valid octal digits (0-7). Example The following example demonstrates how to use octal literals in C − #include int main() { int a = 025; /* Octal 25 = Decimal 21 */ int b = ...
Read Morelvalue and rvalue in C
An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address). An rvalue is defined by exclusion − every expression is either an lvalue or an rvalue, so an rvalue is an expression that does not represent an object occupying some identifiable location in memory. Syntax lvalue = rvalue; // Valid assignment rvalue = lvalue; // Invalid assignment (compilation error) Example 1: Valid lvalue Assignment An assignment expects an lvalue as its left operand. Here's a valid example − #include int ...
Read More