Increment And Decrement Operator in C++ In C++ Programming Language, increasing a value by 1 is called incrementing and decreasing value by 1 is called decrementing. As 1 is the most common value used to add, subtract and to reassign into variable. Although we have short-hand assingnment operator but special operator are provided in c++ programming to increase or decrease value by 1. The increment operator(++) increases the variable's value by 1 and the decrement operator(--) decreases the... Read Full Story
C++ Constant : Types And Uses What is Constant ? As similar to variable constant are data storage location. As the name implies constant's value do not change. They remain constant throughout the program. Unlike variable whose value can be changed anywhere in the program. There are two types of constant in C++. They are as follows : 1) Literal Constant float PI=3.14; The value that is directly typed into the program is called literal constant. Here 3.14 is called literal constant. You cannot... Read Full Story
Short Hand Assignment Operator in C++ Programming Short hand assignemnt operators are also known as compound assignment operator. The advantage of using short hand assignment operator is that it requires less typing and hence provides efficiency. ------------------------------------------------------------------------------------------ A C++ Program example without using short hand assignment operator #include <iostream> #include <conio.h> int main() { using std::cout; using std::endl; int a... Read Full Story
Passing Structures to Functions
Here we can discuss passing structures and their members to functions .
Passing Structure Members to Functions
When you pass a member of a structure to a function , you are actually passing the value of that member to the function . Therefore, you are passing a simple variable (unless, of course, that element is compound, such as an array ). For example, consider this structure:
struct fred
{
char x;
int y;
float z;
char s[10];
} mike;
Here are... Read Full Story
Structures
A structure is a collection of variables referenced under one name, providing a convenient means of keeping related information together. A structure declaration forms a template that may be used to create structure objects (that is, instances of a structure). The variables that make up the structure are called members. (Structure members are also commonly referred to as elements or fields).
Generally, all of the members of a structure are logically related. For example, the... Read Full Story
Structure Assignments
The information contained in one structure may be assigned to another structure of the same type using a single assignment statement. That is, you do not need to assign the value of each member separately. The following program illustrates structure assignments:
#include
int main(void)
{
struct {
int a;
int b;
} x, y;
x.a = 10;
y = x; /* assign one structure to another */
printf(”%d”, y.a);
return 0;
}
After the assignment, y.a will contain the value 10... Read Full Story
I thought the following program was a perfect C program. But on compiling, I found a silly mistake. Can you find it out (without compiling the program :-) ? #include void OS_Solaris_print () { printf ( "Solaris - Sun Microsystems \n " ); } void OS_Windows_print () { printf ( "Windows - Microsoft \n " ); } void OS_HP-UX_print () { printf ( "HP-UX - Hewlett Packard \n " ); } int main () { int num ; printf ( "Enter the number (1-3): \n " ); scanf ( " %d " , & num ); switch ( num ) { case 1... Read Full Story
Function Arguments
If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function . They behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit. As shown in the following function , the parameter declarations occur after the function name:
/* Return 1 if c is part of string s; 0 otherwise. */
int is_in(char *s, char c... Read Full Story
Pointers to Functions
A particularly confusing yet powerful feature of C++ is the function pointer. Even though a function is not a variable , it still has a physical location in memory that can be assigned to a pointer . This address is the entry point of the function and it is the address used when the function is called. Once a pointer points to a function, the function can be called through that pointer . Function pointers also allow functions to be passed as arguments to other... Read Full Story
Returning Pointers
Although functions that return pointers are handled just like any other type of function , a few important concepts need to be discussed.
Pointers to variables are neither integers nor unsigned integers. They are the memory addresses of a certain type of data. The reason for this distinction is because pointer arithmetic is relative to the base type. For example, if an integer pointer is incremented, it will contain a value that is 4 greater than its previous value... Read Full Story