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
C/C++ Macro for string concatenation
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 MoreHow to get distinct values for non-key column fields in Laravel?
In Laravel, you can retrieve distinct values for non-key column fields using several methods. Let's explore different approaches to get unique values from a database table. Assume we have a students table created with the following structure − CREATE TABLE students( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(15) NOT NULL, email ...
Read MoreC program to print a string without any quote in the program
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 MoreHow to select all the column names from a table in Laravel?
In Laravel, you can retrieve column names from a database table using several methods. Laravel provides multiple approaches through the Schema facade, Eloquent models, and DB facade to access table structure information. Assume we have created a table named students in MySQL database using the following query − CREATE TABLE students( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(10) NOT ...
Read MoreC Program to display hostname and IP address
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 MoreC Program to print hollow pyramid and diamond pattern
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 MoreHow to find a user in Laravel by Username?
In Laravel, there are several ways to find a user by username using Eloquent ORM and the database query builder. Each method provides different levels of functionality and data retrieval options. Using the first() Method The first() method returns the first record that matches the search criteria. It returns null if no matching records are found − The output of the above code is − The name exists in the table Using SELECT Query with Specific Fields You can use the select() method to retrieve only specific fields ...
Read MoreC program to print digital clock with current time
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 MoreHow to alias a table in Laravel Eloquent queries using Query Builder?
Laravel Eloquent provides several ways to alias tables in database queries, making your code more readable and enabling complex joins. Table aliases are particularly useful when working with multiple tables or when you need to shorten long table names. Sample Data Let's assume we have a students table with the following data − +----+---------------+------------------+-----------------------------+-----------------------------+---------+------+ | id | name | email | created_at ...
Read MoreC program to write an image in PGM format
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