C Articles

Page 89 of 96

C Program to print hollow pyramid and diamond pattern

George John
George John
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will learn how to create hollow pyramid and diamond patterns in C programming. Unlike solid patterns, hollow patterns print stars only at the borders while keeping the interior empty using spaces. Syntax /* Hollow Pyramid Logic */ for(i = 1; i

Read More

C program to print digital clock with current time

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 3K+ Views

In this section we will see how to make a digital clock using C. To work with time we can use the time.h header file. This header file has some function signatures that are used to handle date and time related issues. The four important components of time.h are like below − size_t − This size_t is basically the unsigned integral type. This is the result of sizeof(). clock_t − This is used to store the processor time time_t − This is used to store calendar time struct tm − This is a structure. It helps to ...

Read More

C program to write an image in PGM format

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 2K+ Views

The PGM (Portable Gray Map) format is part of the Netpbm package that provides an easy way to store 2D arrays as grayscale images. Unlike complex formats like PNG or JPEG, PGM files use a simple ASCII format that makes them easy to create and read programmatically. Each PGM file starts with a magic number P2 (for ASCII encoding) followed by dimensions, maximum gray value, and pixel data. The format is human-readable and portable across different platforms. Syntax P2 width height max_gray_value pixel_values... PGM File Structure To write a PGM file, follow these ...

Read More

C Program to validate an IP address

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 9K+ Views

In this program we will see how to validate an IP address using C. The IPv4 addresses are represented in dot-decimal notation. There are four decimal numbers (all are ranging from 0 to 255). These four numbers are separated by three dots. An example of a valid IP is: 192.168.4.1 Syntax int validate_ip(char *ip); Validation Steps To validate the IP address we should follow these steps − Tokenize the string (IP address) using the dot "." delimiter If the sub strings are containing ...

Read More

C program to print characters without using format specifiers

George John
George John
Updated on 15-Mar-2026 886 Views

In this article we will see how we can print some characters without using any kind of format specifiers. The format specifiers in C are %d, %f, %c etc. These are used to print characters and numbers in C using the printf() function. Here we will see another way to print characters without using %c format specifier. This can be done by putting ASCII values directly in hexadecimal form using escape sequences. Syntax printf("\xHH"); // HH is hexadecimal ASCII value Method 1: Using Hexadecimal Escape Sequences The \x escape sequence allows us ...

Read More

Write a C program that does not terminate when Ctrl+C is pressed

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 2K+ Views

In C, we can create a program that does not terminate when Ctrl+C is pressed by using signal handling. The Ctrl+C key combination generates the SIGINT (Signal Interrupt) signal, which normally terminates a running process. However, we can intercept this signal using the signal() function and define custom behavior instead. Syntax #include void (*signal(int sig, void (*func)(int)))(int); Where sig is the signal number and func is the handler function to be called when the signal is received. Common Signal Types Signal Description SIGABRT Indicates Abnormal ...

Read More

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

Samual Sam
Samual Sam
Updated on 15-Mar-2026 177 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

Why array index starts from zero in C/C++ ?

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 7K+ Views

An array arr[i] is interpreted as *(arr+i). Here, arr denotes the address of the first array element or the 0th index element. So *(arr+i) means the element is at i distance from the first element of the array. Therefore, array index starts from 0 as initially i is 0 which means the first element of the array. In this article, we will see examples of C code to understand the reason why an array starts from index 0. Syntax data_type array_name[array_size]; // Accessing element: array_name[index] where index starts from 0 Why Array Index Starts ...

Read More

Why do we assume strncpy insecure in C/C++?

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 704 Views

The strncpy() function is used to copy a specified number of characters from a source string to a destination string. While it might seem safer than strcpy() because it limits the number of characters copied, strncpy() has several security vulnerabilities that make it unsafe for general use. Syntax char *strncpy(char *destination, const char *source, size_t n); Parameters: destination: Pointer to the destination array where content is to be copied source: Pointer to the source string to be copied n: Maximum number of characters to be copied from source Why strncpy() is Insecure ...

Read More

Accessing array out of bounds in C/C++

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 2K+ Views

An array in C is a fixed-size sequential collection of elements of the same data type where all elements are stored in contiguous memory. When an array is accessed out of bounds, undefined behavior occurs in C, unlike higher-level languages that throw exceptions. Syntax type arrayName[size]; // Valid indices: 0 to (size-1) // Out of bounds: index < 0 or index >= size Accessing Out of Bounds Memory Accessing out-of-bounds memory means trying to access an array index outside its valid range (index < 0 or index >= array size). This returns garbage values ...

Read More
Showing 881–890 of 953 articles
« Prev 1 87 88 89 90 91 96 Next »
Advertisements