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
Server Side Programming Articles
Page 993 of 2109
C Program to find size of a File
The size of a file refers to the number of bytes it occupies in memory. In C, size of a file can be found by moving the file pointer to the end of the file and checking its position. The position indicates the number of bytes the file contains. The most common way to do this is by using two functions: fseek() (to move to the end) and ftell() (to get the current position, which is the size of the file). Syntax FILE *fp = fopen("filename", "rb"); fseek(fp, 0, SEEK_END); long size = ftell(fp); fclose(fp); ...
Read Moreexit() vs _Exit() function in C and C++
In C, both exit() and _Exit() functions terminate a program, but they differ in how they handle cleanup operations. The exit() function performs cleanup operations before termination, while _Exit() terminates immediately without any cleanup. Syntax void exit(int status); void _Exit(int status); The exit() function calls registered cleanup functions (via atexit()), flushes buffers, and closes open streams before termination. The _Exit() function immediately terminates the program without performing any cleanup operations. Example 1: Using exit() Function Here's how exit() executes cleanup functions registered with atexit() − #include #include void ...
Read MoreHow to get the Current URL inside the @if Statement in Laravel?
In Laravel, you can access the current URL within Blade template @if statements using several built-in methods. These methods help you conditionally display content based on the current route or URL. Using Request::path() The Request::path() method returns only the path portion of the URL (without domain) −
Read MoreLevels of Pointers in C/C++
In C, pointers have multiple levels, which means a pointer can point to another pointer − so the chains of indirection can go on and on. For instance, a pointer to a variable's address is stored at "*ptr" (single-level pointer) while, at "**ptr", the address of another pointer is kept (a double-level pointer), and so on. This is useful in allocating memory dynamically, working with multi-dimensional arrays, and handling complicated data structures. Syntax // Single level pointer int *ptr = &variable; // Double level pointer int **pptr = &ptr; // Triple level ...
Read MoreHow do you check if a field is NOT NULL with Eloquent?
In Laravel's Eloquent ORM, you can check if a field is NOT NULL using the whereNotNull() method. This method filters records where the specified column contains non-null values. Syntax The basic syntax for checking NOT NULL fields ? Model::whereNotNull('column_name')->get(); Using Eloquent Model Here's how to check if the remember_token field is NOT NULL using an Eloquent model ? The output of the above code is − Siya Khan Heena Khan Seema The generated SQL query is − SELECT * FROM users WHERE ...
Read MoreStandard Size of character (\'a\') in C/C++ on Linux
In C, every character including 'a' is stored using a specific size in memory. On most systems including Linux, the size of a character is 1 byte. This means that any character (like 'a') occupies 1 byte (8 bits) of memory. To determine how much memory is used by the character 'a', we can use the sizeof() operator, which returns the size in bytes of a variable or data type. Syntax sizeof(expression) sizeof(datatype) Method 1: Using sizeof with Character Literal This approach checks the size of the character literal 'a' using the sizeof() ...
Read MoreHow to add a new value to a collection in Laravel?
Collection in Laravel is an API wrapper that helps you deal with different operations to be performed on arrays. It makes use of the class Illuminate\Support\Collection to deal with arrays in Laravel. To create a collection from a given array you need to make use of the collect() helper method that returns a collection instance. Later you can use a chain of methods like converting to lowercase, sorting on the collection instance. Basic Collection Example Here's how to create a basic collection ? Illuminate\Support\Collection Object( [items:protected] => Array( ...
Read MoreFind out the current working directory in C/C++
To find the Current Working Directory (CWD) in C or C++ is like asking your program: "Hey, where am I right now?". Simply we can say that it is like a folder of your program which is present and used to operate in. We can use functions like getcwd() from unistd.h in C/C++ or filesystem::current_path() from C++17. Below are the list of the ways to achieve this − Using getcwd() in C/C++ Using filesystem in C++17 Using getcwd() Function in C In C, we use the ...
Read MoreHow to check if a user email already exists in Laravel?
In Laravel, checking if a user email already exists is a common requirement for registration, validation, and duplicate prevention. Laravel provides multiple approaches to accomplish this task efficiently. Before running these examples, ensure you have a Laravel project set up with a User model and database connection configured. Using Laravel Validator The Validator class provides a clean way to check email uniqueness using Laravel's built−in validation rules ?
Read MoreSum of array using pointer arithmetic in C
In C programming, we can calculate the sum of array elements using pointer arithmetic. This approach uses pointers to traverse the array and access elements without using array indexing notation. Pointer arithmetic allows us to navigate through memory addresses. When we use *(a + i), it accesses the element at position i from the base address a. This is equivalent to a[i] but demonstrates direct memory manipulation. Syntax int sum = sum + *(pointer + index); Example Here's a complete program that calculates the sum of array elements using pointer arithmetic − ...
Read More