Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 51 of 151

Does Ternary operation exist in MySQL just like C or C++?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 185 Views

Yes, ternary operation exists in MySQL using the CASE WHEN statement, which provides similar conditional logic to the ternary operator in C/C++. Let us first examine how the ternary operator works in C and then see its MySQL equivalent. Syntax C Ternary Operator: condition ? value_if_true : value_if_false MySQL Equivalent: CASE WHEN condition THEN value_if_true ELSE value_if_false END Example: C Ternary Operator Here is a complete C program demonstrating the ternary operator − #include int main() { int X = 5; ...

Read More

What is the difference between g++ and gcc?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

The gcc and g++ are both GNU compiler collection tools, but they serve different purposes. gcc is primarily designed for C programs, while g++ is designed for C++ programs. Understanding their differences helps choose the right compiler for your project. Syntax gcc program.c -o executable_name g++ program.cpp -o executable_name gcc (GNU C Compiler) The gcc compiler is specifically designed to compile C programs. It treats files with .c extension as C source code and links against the standard C library by default. Example: Using gcc for C Program #include ...

Read More

Swapping two variable value without using third variable in C/C++

Samual Sam
Samual Sam
Updated on 15-Mar-2026 600 Views

In C programming, swapping two variables without using a third variable can be accomplished using arithmetic operations. This technique saves memory and demonstrates clever use of mathematical operations. Syntax a = a + b; b = a - b; a = a - b; Method 1: Using Addition and Subtraction This approach uses arithmetic operations to swap values without requiring additional memory − #include int main() { int a = 10, b = 20; printf("Before swapping: a ...

Read More

C function to Swap strings

Samual Sam
Samual Sam
Updated on 15-Mar-2026 827 Views

In C programming, swapping strings involves exchanging the contents of two string variables. This can be achieved through character-by-character swapping or by swapping string pointers. Syntax // Character-by-character swapping void swapStrings(char str1[], char str2[]); // Pointer swapping void swapPointers(char **str1, char **str2); Method 1: Character-by-Character Swapping This method swaps each character of the strings individually − #include #include int main() { char st1[] = "My 1st string"; char st2[] = "My 2nd string"; char swap; ...

Read More

Return values of printf() and scanf() in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 13K+ Views

The printf() and scanf() functions are required for output and input respectively in C. Both of these functions are library functions and are defined in the stdio.h header file. Understanding their return values is crucial for error handling and program flow control. Syntax int printf(const char *format, ...); int scanf(const char *format, ...); The printf() Function Return Value The printf() function returns the number of characters that are printed successfully. If there is an error during output, it returns a negative value. Example #include int main() { ...

Read More

Static functions in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 21K+ Views

A static function in C is a function that has a scope limited to its object file. This means the static function is only visible within the file where it is defined and cannot be accessed from other files. A function can be declared as static by placing the static keyword before the function name. Syntax static return_type function_name(parameters) { // function body } Example 1: Static Function in Same File Here's an example demonstrating a static function called within the same file − #include static ...

Read More

How to clear console in C?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 22K+ Views

In C, clearing the console or output screen can be achieved using several methods. While clrscr() from conio.h was commonly used in older compilers, modern standard C uses system() calls for cross-platform compatibility. Note: The examples below use system() calls which work in most environments. For online compilers, console clearing may not be visible as output is captured after program execution. Syntax The following are standard methods to clear the console in C − #include system("cls"); /* Windows */ Or, #include system("clear"); /* ...

Read More

Print contents of a file in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 7K+ Views

In C, printing the contents of a file involves opening the file, reading its data character by character or line by line, and displaying it on the console. The fopen(), fgetc(), and fclose() functions are commonly used for this purpose. Syntax FILE *fopen(const char *filename, const char *mode); int fgetc(FILE *stream); int fclose(FILE *stream); Method 1: Reading Character by Character Let's say we have "new.txt" file with the following content − 0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demo Note: Create a file named "new.txt" in your working directory ...

Read More

fseek() vs rewind() in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

In C, both fseek() and rewind() are used to change the position of the file pointer, but they serve different purposes. fseek() provides flexible positioning anywhere in the file, while rewind() specifically moves the pointer back to the beginning. fseek() Function The fseek() function moves the file pointer to a specific position based on an offset and reference point. Syntax int fseek(FILE *stream, long int offset, int whence) Here are the parameters − stream − Pointer to the FILE object offset − Number of bytes to move from the reference position ...

Read More

fgets() and gets() in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

In C, fgets() and gets() are functions used to read strings from input streams. The key difference is that fgets() is safe and checks array bounds, while gets() is unsafe and has been removed from C11 standard due to buffer overflow vulnerabilities. fgets() Function The fgets() function reads a string from a specified stream until a newline character or the specified limit is reached − Syntax char *fgets(char *string, int size, FILE *stream); Parameters: string − Pointer to character array where the string will be stored size − Maximum number of characters ...

Read More
Showing 501–510 of 1,507 articles
« Prev 1 49 50 51 52 53 151 Next »
Advertisements