Programming Articles

Page 1011 of 2547

C/C++ Macro for string concatenation

Farhan Muhamed
Farhan Muhamed
Updated on 15-Mar-2026 6K+ Views

In C programming, macros provide a powerful way to concatenate strings at compile-time using the preprocessor. This technique allows for efficient string manipulation without runtime overhead, making it particularly useful for creating constants, debug messages, and code generation. Syntax /* String literal concatenation */ #define STRING1 "First part" #define STRING2 "Second part" #define CONCATENATED STRING1 STRING2 /* Token concatenation using ## operator */ #define CONCAT_TOKENS(a, b) a##b Understanding Macros in C In C, macros are preprocessor directives defined using #define. They are expanded before compilation, replacing every occurrence with the defined value. Macros ...

Read More

C program to print a string without any quote in the program

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 865 Views

This is another tricky problem. In this program, we will see how to print a string using C where no quotation marks are used in the source code. Here we are using a macro function with the stringizing operator. We define a macro function that converts its argument into a string literal at compile time. Syntax #define getString(x) #x The getString() is a macro function that returns x by converting it into a string. The # before x is the stringizing operator that converts the macro argument into a string literal. Example ...

Read More

C Program to display hostname and IP address

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

In C, we can retrieve the hostname and IP address of the local system using socket programming functions. This is useful for network programming and system administration tasks. Syntax int gethostname(char *name, size_t len); struct hostent *gethostbyname(const char *name); char *inet_ntoa(struct in_addr in); Key Functions Function Description gethostname() Retrieves the standard hostname for the local computer gethostbyname() Finds host information corresponding to a hostname from host database inet_ntoa() Converts an IPv4 network address into ASCII dotted decimal format ...

Read More

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 897 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

Data Types we cannot use to create array in C

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 435 Views

In C programming, arrays can be created using most data types like int, char, float, double, etc. However, there are certain data types that cannot be used to create arrays. The most notable restriction is with the void data type. Syntax datatype array_name[size]; // Valid for most data types void array_name[size]; // Invalid - compilation error Data Types That Cannot Be Used for Arrays 1. Void Data Type The void data type represents "no type" and has no size. Since arrays need to know the size of ...

Read More
Showing 10101–10110 of 25,466 articles
Advertisements