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 915 of 2109
Write a C program to demonstrate post increment and pre increment operators
In C programming, the increment (++) and decrement (--) operators are used to increase or decrease a variable's value by 1. These operators can be applied in two forms: pre-increment/decrement and post-increment/decrement, which behave differently in expressions. Syntax /* Pre-increment/decrement */ ++variable; --variable; /* Post-increment/decrement */ variable++; variable--; Pre-Increment Operator (++variable) In pre-increment, the operator is placed before the operand. The value is first incremented and then the operation is performed on it. For example − z = ++a; // First: a = a + 1, Then: ...
Read MoreWrite C program using isupper() function
In C, the isupper() function is used to check if a character is an uppercase letter (A-Z). It is defined in the ctype.h header file and returns a non-zero value if the character is uppercase, otherwise returns 0. Syntax int isupper(int ch); Parameters: ch − The character to be checked (passed as int). Return Value: Non-zero if the character is uppercase, 0 otherwise. Example 1: Counting Uppercase Letters Using isupper() This program counts the total number of uppercase letters in a string using the isupper() function − #include #include ...
Read MoreWrite a C program using time.h library function
The time.h library in C provides various functions to work with date and time. This library allows you to get the current system time, format it, and perform time-related calculations. Syntax #include time_t time(time_t *timer); char *strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr); struct tm *localtime(const time_t *timer); Key Functions time() − Returns the current time as seconds since January 1, 1970 (Unix timestamp) strftime() − Formats time into a string according to specified format specifiers localtime() − Converts time_t to local time structure (struct tm) ...
Read MoreWrite a C program to check the atexit() function
The atexit() is a function that allows the user to register a function that has to be called when the program terminates normally. These registered functions are called in the reverse order of their registration. It is a predefined function that is included in the stdlib.h header file. Syntax int atexit(void (*function)(void)); Parameters: function − Pointer to a function that takes no parameters and returns no value. Return Value: Returns 0 on success, non-zero on failure. Example 1: Basic Usage This example demonstrates how atexit() calls registered functions in ...
Read MoreCalculate interest amount by using formula in C language
In C programming, calculating interest on deposited amounts is a common financial calculation. This program demonstrates how to compute the final amount after applying continuous compound interest over a specified period. Syntax A = P * exp((r/100) * t) Where: P = Principal amount (initial deposit) r = Annual interest rate (percentage) t = Time period in years A = Final amount after interest Algorithm START Step 1: Declare double variables P, r, t, A, M Step 2: Read principal amount to be deposited Step 3: Read annual interest rate ...
Read MoreExplain the functions fread() and fwrite() used in files in C
In C programming, fread() and fwrite() functions are used for binary file operations to read and write entire structures or data blocks at once. These functions are particularly useful when working with structured data like records. Syntax size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); Parameters ptr − Pointer to the memory location to read/write data size − Size of each element in bytes nmemb − Number of elements to read/write stream − File pointer Return Value Both functions ...
Read MoreConcatenating n characters from source string to destination string in C
In C programming, the strncat() function is used to concatenate a specified number of characters from a source string to the end of a destination string. This function provides more control than strcat() by allowing you to limit the number of characters to be concatenated. Syntax char *strncat(char *dest, const char *src, size_t n); Parameters dest − Pointer to the destination string src − Pointer to the source string n − Maximum number of characters to concatenate Example 1: Basic strncat() Usage This example demonstrates concatenating only 4 characters from ...
Read MoreWrite a C program to read a data from file and display
In C programming, reading data from a file and displaying it is a fundamental file handling operation. This involves opening a file in read mode, reading its contents character by character, and formatting the output for better readability. Syntax FILE *fopen(const char *filename, const char *mode); int getc(FILE *stream); int fclose(FILE *stream); File Opening Modes Write mode ("w"): FILE *fp; fp = fopen("sample.txt", "w"); If the file does not exist, then a new file will be created. If the file exists, then old content gets erased and current content will ...
Read MoreWrite a C program to display the size and offset of structure members
In C programming, structures allow us to group different data types under a single name. When working with structures, it's important to understand how memory is allocated for each member and their positions within the structure. The sizeof() operator helps determine the size of structure members, while the offsetof() macro shows the byte offset of each member from the beginning of the structure. Syntax struct structure_name { datatype member1; datatype member2; datatype memberN; }; sizeof(variable_or_type) offsetof(struct_type, member_name) Structure Declaration A structure ...
Read MoreLegal and illegal declaration and initializations in C
In C programming, variable declaration and initialization must follow specific rules. Understanding legal and illegal practices helps write error-free code and avoid compilation issues. Syntax // Variable Declaration datatype variable1, variable2, ..., variableN; // Variable Initialization datatype variable = value; Variable Declaration Variables can be declared in two scopes − Global declaration: Variables declared outside any function, accessible throughout the program. Local declaration: Variables declared inside a function, accessible only within that function. #include int globalVar; /* global declaration */ int main() { ...
Read More