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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Use of bool in C
In C, there is no predefined datatype as bool. However, we can create a boolean type using enum or use the standard header (C99 and later). With enum, we create a boolean type where false holds value 0 and true holds value 1. Syntax typedef enum { false, true } bool; // Or using C99 standard #include Method 1: Using Enum We can create a custom boolean type using typedef enum − #include typedef enum { false, true } bool; int main() { ...
Read MorePHP Program to Count Trailing Zeroes in Factorial of a Number
The factorial of a non-negative integer, denoted by the symbol "!", is the product of all positive integers less than or equal to that number. In other words, the factorial of a number is obtained by multiplying that number by all the positive integers below it. For example, the factorial of 5 is calculated as: 5! = 5 x 4 x 3 x 2 x 1 = 120 Similarly, the factorial of 0 is defined to be 1: 0! = 1 What are Trailing Zeroes? In the factorial of a number, trailing zeroes refer ...
Read MoreHow to write a running C code without main()?
In C programming, it is possible to write a program without the traditional main() function. While main() appears to be the entry point from a programmer's perspective, the system actually calls _start() first, which sets up the environment before calling main(). Syntax int _start() { // Program code here _exit(status_code); } Note: To compile programs without main(), use the -nostartfiles flag with gcc to skip the standard startup files that expect a main() function. Example Here's how to create a C program using ...
Read MorePrint a long int in C using putchar() only
Here we will see how to print long int value using the putchar() function in C. We can easily print the value of some variables using printf() in C, but here the restriction is, we cannot use any other function except putchar(). As we know that the putchar() is used to print only characters. We can use this function to print each digit of the number. When one numeric value is passed, we have to add character '0' with it to get the ASCII form. Syntax void print_long(long value); int putchar(int character); Example ...
Read MorePHP Program to Count set Bits in an Integer
In PHP, counting set bits (1s) in an integer's binary representation is a common programming task. A set bit refers to a binary digit that has the value 1, while a clear bit has the value 0. For example, the number 12 in binary is 1100, which has 2 set bits. What is Binary Code? Binary code is a system of representing information using a base-2 numeral system. It uses only two digits, 0 and 1, to represent all values. Each digit in binary code is called a bit (short for binary digit). In binary code, each ...
Read MoreHow 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 MorePHP Program to Count Page Views
In PHP, counting page views is a common requirement for tracking user engagement and website analytics. This can be achieved using sessions to maintain a counter that persists across multiple page visits for each user session. What is Session? In PHP, a session is a way to store and persist data across multiple requests or page views for a specific user. When a user visits a website, a unique session ID is assigned to them, typically stored as a cookie on the user's browser. This session ID is used to associate subsequent requests from the same user with ...
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 MorePHP Program to Count Number of Binary Strings without Consecutive 1’s
In PHP, counting binary strings without consecutive 1's is a classic dynamic programming problem. A binary string contains only 0's and 1's, and we need to count valid strings where no two 1's appear next to each other. Understanding the Problem Let's analyze binary strings of length 3 to understand the pattern − All possible binary strings of length 3: 000, 001, 010, 011, 100, 101, 110, 111 Valid strings (without consecutive 1's): 000, 001, 010, 100 Invalid strings (with consecutive 1's): 011, 110, 111 So for length 3, we have 5 valid binary strings ...
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 More