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 94 of 96
Float and Double in C
In C programming, float and double are data types used to represent floating point numbers. Both follow the IEEE 754 standard but differ in precision and memory usage. Float Data Type Float is a 32-bit IEEE 754 single precision floating point number with the following structure − 1 bit for the sign 8 bits for the exponent 23 bits for the mantissa (fractional part) Precision: 6-7 decimal digits Syntax float variable_name; Example: Float Declaration and Usage #include int main() { float x ...
Read MoreDifference between getc(), getchar(), getch() and getche()
All these functions read characters from input and return an integer. They differ in their source, buffering behavior, and echo characteristics. Syntax int getc(FILE *stream); int getchar(void); int getch(void); /* Non-standard */ int getche(void); /* Non-standard */ getc() The getc() function reads a single character from a specified file stream and returns it as an integer. It waits for the Enter key and uses buffered input. Example #include int main() { char val; printf("Enter the character: ...
Read MoreHow to print % using printf()?
In C, the printf() function uses the percent symbol (%) as a format specifier. To print the actual % character as text, you need to use a double percent (%%) because a single % has special meaning in printf() and will not display anything. Syntax printf("%%"); // Prints a single % character Example 1: Basic % Printing Here's how to print the % symbol using printf() − #include int main() { printf("Single percent: %%"); printf("Percentage: 85%%"); printf("Multiple: ...
Read More"register" keyword in C
In C programming, the register keyword is a storage class specifier that suggests to the compiler to store a variable in CPU registers instead of main memory. Register variables provide faster access since CPU registers are much faster than memory. However, taking the address of a register variable is not allowed. Syntax register data_type variable_name; Properties of Register Variables Scope: Local to the function in which they are declared Default value: Garbage value (uninitialized) Lifetime: Until the end of the block execution Storage: CPU registers (compiler's choice) Address: Cannot use address-of operator (&) ...
Read More"extern" keyword in C
The extern keyword in C is used to declare variables and functions that are defined elsewhere, either in the same file or in other source files. It extends the visibility of variables and functions across multiple files, making them globally accessible. Syntax extern data_type variable_name; extern data_type function_name(parameters); Key Properties Scope − Global throughout the program, not bound by any function. Default value − Global variables are initialized to zero by default. Lifetime − Exists until the end of program execution. Important Points External variables can be declared multiple times but ...
Read MoreCount spaces, uppercase and lowercase in a sentence using C
In C programming, counting different types of characters in a string is a common task. This involves analyzing each character to determine if it's uppercase, lowercase, a digit, whitespace, or a special character. Syntax for (int i = 0; str[i] != '\0'; i++) { // Check character type using ASCII values if (str[i] >= 'A' && str[i] = 'a' && str[i] = '0' && str[i] = 'A' && str[i] = 'a' && str[i] = '0' && str[i]
Read MoreHow to convert a string to a integer in C
In C programming, converting a string to an integer is a common task that can be accomplished using several built-in functions. The most commonly used functions are atoi(), strtol(), and sscanf(). Syntax int atoi(const char *str); long strtol(const char *str, char **endptr, int base); int sscanf(const char *str, const char *format, ...); Method 1: Using atoi() Function The atoi() function converts a string to an integer. It stops reading when it encounters a non-digit character − #include #include int main() { char str[] = "12345"; ...
Read MoreList of Common Reasons for Segmentation Faults in C/C++
The main reason for segmentation fault is accessing memory that is either not initialized, out of bounds for your program or trying to modify string literals. These may cause a segmentation fault though it is not guaranteed that they will cause a segmentation fault. Here are some of the common reasons for segmentation faults − Accessing an array out of bounds Dereferencing NULL pointers Dereferencing freed memory Dereferencing uninitialized pointers Incorrect use of the "&" (address of) and "*" (dereferencing) operators Improper formatting specifiers in printf and scanf statements Stack overflow Writing to read-only memory Common ...
Read MoreHow does the compilation/linking process work in C/C++?
The compilation of a C program involves several distinct phases that transform source code into an executable program. Understanding this process helps debug compilation errors and optimize build workflows. Compilation Process Overview Source Code (main.c) Preprocessor (main.i) Compiler (main.s) Assembler (main.o) Linker (executable) ...
Read MoreWhat is a segmentation fault in C/C++?
A segmentation fault (commonly called "segfault") occurs when your program attempts to access an area of memory that it is not allowed to access. In other words, when your program tries to access memory that is beyond the limits that the operating system allocated for your program. Segmentation faults are one of the most common runtime errors in C programming and cause the program to terminate immediately with an error message. Common Causes Seg faults are mostly caused by pointers that are − Used without being properly initialized. Used after the memory they point to ...
Read More