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 81 of 96
How to count set bits in a floating point number in C?
In this problem, one floating point value is given. We have to find the number of set bits in the binary representation of it. This involves analyzing the IEEE 754 single-precision floating point format used by C compilers. For example, if a floating point number is 0.15625, there are six set bits in its 32-bit binary representation. The IEEE 754 format consists of 1 sign bit, 8 exponent bits, and 23 mantissa bits. IEEE 754 Single Precision Format (32 bits) S ...
Read MoreHow will implement Your Own sizeof in C
In C, the sizeof operator returns the size in bytes of a variable or data type. We can implement our own version of sizeof using pointer arithmetic. The concept is based on the fact that when we increment a pointer by 1, it moves by the size of the data type it points to. Syntax #define my_sizeof(variable) (char *)(&variable+1)-(char*)(&variable) How It Works The implementation uses pointer arithmetic − &variable gives the address of the variable &variable+1 gives the address after one complete element Casting both to (char*) makes the subtraction return bytes ...
Read MoreHow will you show memory representation of C variables?
In C programming, understanding the memory representation of variables is crucial for debugging and low-level programming. This involves examining how different data types are stored in memory at the byte level. Syntax typedef unsigned char *byte_pointer; void display_bytes(byte_pointer ptr, int length); Algorithm To display memory representation of C variables, follow these steps − Get the address and size of the variable using & operator and sizeof() Typecast the address to unsigned char* to access individual bytes Loop through each byte and print its hexadecimal value Example: Memory Representation of Different ...
Read MoreImplicit return type int in C
In C, if a function is declared without an explicit return type, the compiler implicitly assumes the return type to be int. This behavior was allowed in older C standards (C89/C90) but is deprecated and not recommended. The C99 standard requires explicit return types for all functions. Syntax function_name(parameters) { /* Function body */ return value; /* Implicitly returns int */ } Example: Implicit Return Type Here's an example demonstrating implicit return type behavior − #include my_function(int x) { ...
Read MoreDifference between char s[] and char *s in C
In C programming, there are two common ways to declare strings: char s[] and char *s. While both can hold strings, they have fundamental differences in memory allocation, mutability, and behavior. Syntax char s[] = "string literal"; // Array declaration char *s = "string literal"; // Pointer declaration Key Differences Aspect char s[] char *s Type Array of characters Pointer to char Memory Location Stack (local array) Pointer on stack, string in read-only section Mutability Modifiable Read-only ...
Read MoreVariable length arguments for Macros in C
In C, we can use variable length arguments for macros, similar to how we use them with functions. This is achieved using ellipsis (…) and the special __VA_ARGS__ identifier. The concatenation operator ## is used to handle cases where no variable arguments are provided. Syntax #define MACRO_NAME(fixed_params, ...) macro_body __VA_ARGS__ Where __VA_ARGS__ represents all the variable arguments passed to the macro, and ## can be used for token pasting. Example: Logging Macro with Variable Arguments This example demonstrates a logging macro that accepts variable arguments like printf(). The macro prints the filename, line ...
Read MoreDifference between "int main()" and "int main(void)" in C/C++?
In C programming, you might notice two different ways to declare the main function: int main() and int main(void). While both are valid, there is a subtle but important difference in how C treats them. Syntax int main() int main(void) Key Difference In C, int main() means the function can accept any number of arguments, while int main(void) explicitly specifies that the function takes no arguments. In C++, both forms are equivalent and mean "no arguments". Example 1: Function Without void When a function is declared without void, C allows it to ...
Read MoreWhat is long long in C/C++?
In C programming, long long is an extended integer data type that provides a larger range for storing integer values than the standard long type. The long long type was introduced in C99 standard to handle very large integer values that exceed the capacity of regular int or long types. Syntax long long variable_name; long long int variable_name; // equivalent to above Size and Range The long long data type is guaranteed to be at least 64 bits (8 bytes) according to the C standard. The exact size may vary between systems, but it's ...
Read MoreCheck input character is alphabet, digit or special character in C
In this section, we will see how to check whether a given character is a number, alphabet, or special character in C. We can classify characters by checking their ASCII values against specific ranges. The alphabets are from A – Z and a – z, numbers are from 0 – 9, and all other characters are considered special characters. Syntax if((ch >= 'A' && ch = 'a' && ch = '0' && ch = 'A' && ch = 'a' && ch = '0' && ch
Read Morekbhit in C language
The kbhit() function in C checks if a key has been pressed on the keyboard without waiting for the Enter key. It returns a non-zero value if a key is available to be read, otherwise returns zero. However, kbhit() is non-standard and platform-specific (Windows/DOS only). Syntax int kbhit(void); Parameters None: The function takes no parameters. Return Value Returns a non-zero value if a key has been pressed. Returns zero if no key is pressed. Example Note: This example uses Windows-specific headers (conio.h) and will not ...
Read More