Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C++ Programming Code Examples

C++ > Code Snippets Code Examples

Map erase

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* Map erase */ #include <map> #include <iostream> using namespace std; class Data { public: Data(int val = 0) { mVal = val; } int getVal() const { return mVal; } void setVal(int val) {mVal = val; } protected: int mVal; }; int main(int argc, char** argv) { map<int, Data> dataMap; dataMap[1] = Data(4); cout << "There are " << dataMap.count(1) << " elements with key 1\n"; dataMap.erase(1); cout << "There are " << dataMap.count(1) << " elements with key 1\n"; return (0); }
Classes and Objects in C++ Language
The main purpose of C++ programming is to add object orientation to the C programming language and classes are the central feature of C++ that supports object-oriented programming and are often called user-defined types. A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.
C++ Class Definitions
When you define a class, you define a blueprint for a data type. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object. A class definition starts with the keyword class followed by the class name; and the class body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations. For example, we defined the Box data type using the keyword class as follows:
class Box { public: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box };
The keyword public determines the access attributes of the members of the class that follows it. A public member can be accessed from outside the class anywhere within the scope of the class object. You can also specify the members of a class as private or protected which we will discuss in a sub-section.
Define C++ Objects
A class provides the blueprints for objects, so basically an object is created from a class. We declare objects of a class with exactly the same sort of declaration that we declare variables of basic types. Following statements declare two objects of class Box:
Box Box1; // Declare Box1 of type Box Box Box2; // Declare Box2 of type Box
Both of the objects Box1 and Box2 will have their own copy of data members.
Accessing the Data Members
The public data members of objects of a class can be accessed using the direct member access operator (.). It is important to note that private and protected members can not be accessed directly using direct member access operator (.).
Classes and Objects in Detail
There are further interesting concepts related to C++ Classes and Objects which we will discuss in various sub-sections listed below: • Class Member Functions: A member function of a class is a function that has its definition or its prototype within the class definition like any other variable. • Class Access Modifiers: A class member can be defined as public, private or protected. By default members would be assumed as private. • Constructor & Destructor: A class constructor is a special function in a class that is called when a new object of the class is created. A destructor is also a special function which is called when created object is deleted. • Copy Constructor: The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. • Friend Functions: A friend function is permitted full access to private and protected members of a class. • Inline Functions: With an inline function, the compiler tries to expand the code in the body of the function in place of a call to the function. • this Pointer: Every object has a special pointer this which points to the object itself. • Pointer to C++ Classes: A pointer to a class is done exactly the same way a pointer to a structure is. In fact a class is really just a structure with functions in it. • Static Members of a Class: Both data members and function members of a class can be declared as static.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* using public and private in C++ Class */ // Program to illustrate the working of // public and private in C++ Class #include <iostream> using namespace std; class Room { private: double length; double breadth; double height; public: // function to initialize private variables void initData(double len, double brth, double hgt) { length = len; breadth = brth; height = hgt; } double calculateArea() { return length * breadth; } double calculateVolume() { return length * breadth * height; } }; int main() { // create object of Room class Room room1; // pass the values of private variables as arguments room1.initData(42.5, 30.8, 19.2); cout << "Area of Room = " << room1.calculateArea() << endl; cout << "Volume of Room = " << room1.calculateVolume() << endl; return 0; }
Map Library erase() Function in C++
Erase elements. Removes from the map container either a single element or a range of elements ([first,last)). The C++ map::erase function is used to delete either a single element or a range of elements from the map. It reduces the size of the map by number of elements deleted from the container. This effectively reduces the container size by the number of elements removed, which are destroyed.
Syntax for Map erase() Function in C++
#include <map> //(1) iterator erase (const_iterator position); //(2) size_type erase (const key_type& k); //(3) iterator erase (const_iterator first, const_iterator last);
position
Iterator pointing to a single element to be removed from the map. This shall point to a valid and dereferenceable element. Member types iterator and const_iterator are bidirectional iterator types that point to elements.
k
Key of the element to be removed from the map. Member type key_type is the type of the elements in the container, defined in map as an alias of its first template parameter (Key).
first, last
Iterators specifying a range within the map container to be removed: [first,last). i.e., the range includes all the elements between first and last, including the element pointed by first but not the one pointed by last. Member types iterator and const_iterator are bidirectional iterator types that point to elements. For the key-based version (2), the function returns the number of elements erased. Member type size_type is an unsigned integral type. The other versions return an iterator to the element that follows the last element removed (or map::end, if the last element was removed). Member type iterator is a bidirectional iterator type that points to an element.
Complexity
For the first version (erase(position)), amortized constant. For the second version (erase(val)), logarithmic in container size. For the last version (erase(first,last)), linear in the distance between first and last.
Iterator validity
Iterators, pointers and references referring to elements removed by the function are invalidated. All other iterators, pointers and references keep their validity.
Data races
The container is modified. The elements removed are modified. Concurrently accessing other elements is safe, although iterating ranges in the container is not.
Exception safety
Unless the container's comparison object throws, this function never throws exceptions (no-throw guarantee). Otherwise, if a single element is to be removed, there are no changes in the container in case of exception (strong guarantee). Otherwise, the container is guaranteed to end in a valid state (basic guarantee). If an invalid position or range is specified, it causes undefined behavior.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/* map::erase() is a built-in function in C++ STL which is used to erase element from the container. It can be used to erase keys, elements at any specified position or a given range. */ /* remove either a single element associated with a given key value or a range of elements from the map container by map erase() function code example. */ #include <iostream> #include <map> using namespace std; int main (){ map<int, string> MyMap; map<int, string>::iterator it; //populating map MyMap[101] = "John"; MyMap[102] = "Marry"; MyMap[103] = "Kim"; MyMap[104] = "Jo"; MyMap[105] = "Ramesh"; cout<<"MyMap contains: \n "; for(it = MyMap.begin(); it != MyMap.end(); ++it) cout<<it->first<<" "<<it->second<<"\n "; //version 1: deletes element at position = 2 it = MyMap.begin(); it++; MyMap.erase(it); //version 2: deletes key=104 from the map MyMap.erase(104); cout<<"\nMyMap contains: \n "; for(it = MyMap.begin(); it != MyMap.end(); ++it) cout<<it->first<<" "<<it->second<<"\n "; return 0; }
Map Library count() Function in C++
Count elements with a specific key. Searches the container for elements with a key equivalent to k and returns the number of matches. The map::count() is a built-in function in C++ STL which returns 1 if the element with key K is present in the map container. It returns 0 if the element with key K is not present in the container. Because all elements in a map container are unique, the function can only return 1 (if the element is found) or zero (otherwise). Two keys are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the keys are passed as arguments).
Syntax for Map count() Function in C++
#include <map> size_type count (const key_type& k) const;
k
Key to search for. Member type key_type is the type of the element keys in the container, defined in map as an alias of its first template parameter (Key). Function returns 1 if the container contains an element whose key is equivalent to k, or zero otherwise. Member type size_type is an unsigned integral type.
Complexity
Logarithmic in size
Iterator validity
No changes
Data races
The container is accessed. No mapped values are accessed: concurrently accessing or modifying elements is safe.
Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the container.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* The map::count() is a function which comes under <map> header file. This function counts the elements with specific key, it returns 1 if the element with key is present, It returns the 0 if the element with key is not present in container. */ /* Count elements with a specific key by map count() function code example */ #include <iostream> #include <map> using namespace std; int main (){ map<int, string> MyMap; map<int, string>::iterator it; MyMap[101] = "John"; MyMap[102] = "Marry"; MyMap[103] = "Kim"; MyMap[104] = "Jo"; MyMap[105] = "Ramesh"; for(int i=103; i<108; i++) { if(MyMap.count(i)==0) cout<<i<<" is not a key of MyMap.\n"; else cout<<i<<" is a key of MyMap.\n"; } return 0; }
Constructors in C++ Language
In C++, constructor is a special method which is invoked automatically at the time of object creation. It is used to initialize the data members of new object generally. The constructor in C++ has the same name as class or structure. Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object. Whereas, Destructor on the other hand is used to destroy the class object. • Default Constructor: A constructor which has no argument is known as default constructor. It is invoked at the time of creating object.
Syntax for Default Constructor in C++
class_name(parameter1, parameter2, ...) { // constructor Definition }
• Parameterized Constructor: In C++, a constructor with parameters is known as a parameterized constructor. This is the preferred method to initialize member data. These are the constructors with parameter. Using this Constructor you can provide different values to data members of different objects, by passing the appropriate values as argument.
Syntax for Parameterized Constructor in C++
class class_name { public: class_name(variables) //Parameterized constructor declared. { } };
• Copy Constructors: These are special type of Constructors which takes an object as argument, and is used to copy values of data members of one object into other object.
Syntax for Copy Constructors in C++
classname (const classname &obj) { // body of constructor }
The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to - • Initialize one object from another of the same type. • Copy an object to pass it as an argument to a function. • Copy an object to return it from a function. If a copy constructor is not defined in a class, the compiler itself defines one.If the class has pointer variables and has some dynamic memory allocations, then it is a must to have a copy constructor. The most common form of copy constructor is shown here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* A constructor is a special type of member function that is called automatically when an object is created. In C++, a constructor has the same name as that of the class and it does not have a return type. */ #include <iostream> using namespace std; // declare a class class Wall { private: double length; double height; public: // initialize variables with parameterized constructor Wall(double len, double hgt) { length = len; height = hgt; } // copy constructor with a Wall object as parameter // copies data of the obj parameter Wall(Wall &obj) { length = obj.length; height = obj.height; } double calculateArea() { return length * height; } }; int main() { // create an object of Wall class Wall wall1(10.5, 8.6); // copy contents of wall1 to wall2 Wall wall2 = wall1; // print areas of wall1 and wall2 cout << "Area of Wall 1: " << wall1.calculateArea() << endl; cout << "Area of Wall 2: " << wall2.calculateArea(); return 0; }
Maps in C++ Language
Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. Maps are part of the C++ STL (Standard Template Library). Maps are the associative containers that store sorted key-value pair, in which each key is unique and it can be inserted or deleted but cannot be altered. Values associated with keys can be changed. The key values are good for sorting and identifying elements uniquely. The mapped values are for storing content associated with the key. The two may differ in types, but the member type combines them via a pair type that combines both.
Syntax for Map in C++
template < class Key, // map::key_type class T, // map::mapped_type class Compare = less<Key>, // map::key_compare class Alloc = allocator<pair<const Key,T> > // map::allocator_type > class map;
key
The key data type to be stored in the map.
type
The data type of value to be stored in the map.
compare
A comparison class that takes two arguments of the same type bool and returns a value. This argument is optional and the binary predicate less<"key"> is the default value.
alloc
Type of the allocator object. This argument is optional and the default value is allocator. Maps can easily be created using the following statement:
typedef pair<const Key, T> value_type;
The above form will use to create a map with key of type Key type and value of type value type. One important thing is that key of a map and corresponding values are always inserted as a pair, you cannot insert only key or just a value in a map. • begin: Returns an iterator pointing to the first element in the map. • cbegin: Returns a const iterator pointing to the first element in the map. • end: Returns an iterator pointing to the past-end. • cend: Returns a constant iterator pointing to the past-end. • rbegin: Returns a reverse iterator pointing to the end. • rend: Returns a reverse iterator pointing to the beginning. • crbegin: Returns a constant reverse iterator pointing to the end. • crend: Returns a constant reverse iterator pointing to the beginning. • empty: Returns true if map is empty. • size: Returns the number of elements in the map. • max_size: Returns the maximum size of the map. • operator[]: Retrieve the element with given key. • at: Retrieve the element with given key. • insert: Insert element in the map. • erase: Erase elements from the map. • swap: Exchange the content of the map. • clear: Delete all the elements of the map. • emplace: Construct and insert the new elements into the map. • emplace_hint: Construct and insert new elements into the map by hint. • key_comp: Return a copy of key comparison object. • value_comp: Return a copy of value comparison object. • find: Search for an element with given key. • count: Gets the number of elements matching with given key. • lower_bound: Returns an iterator to lower bound. • upper_bound: Returns an iterator to upper bound. • equal_range: Returns the range of elements matches with given key. • get_allocator Returns an allocator object that is used to construct the map. • operator==: Checks whether the two maps are equal or not. • operator!=: Checks whether the two maps are equal or not. • operator<: Checks whether the first map is less than other or not. • operator<=: Checks whether the first map is less than or equal to other or not. • operator>: Checks whether the first map is greater than other or not. • operator>=: Checks whether the first map is greater than equal to other or not. • swap(): Exchanges the element of two maps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/* how to implement maps in C++ language*/ #include <iostream> #include <iterator> #include <map> using namespace std; int main() { map<int, int> marks; marks.insert(pair<int, int>(160, 42)); marks.insert(pair<int, int>(161, 30)); marks.insert(pair<int, int>(162, 40)); marks.insert(pair<int, int>(163, 50)); marks.insert(pair<int, int>(164, 31)); marks.insert(pair<int, int>(165, 12)); marks.insert(pair<int, int>(166, 34)); map<int, int>::iterator itr; cout << "nThe map marks is : n"; cout << "ROLL NO.tMarksn"; for (itr = marks.begin(); itr != marks.end(); ++itr) { cout << itr->first << "t t" << itr->second << 'n'; } cout << endl; int num; num = marks.erase(164); cout << "nmarks.erase(164) : "; cout << num << " removed n"; cout << "tROLL NO. tMarksn"; for (itr = marks.begin(); itr != marks.end(); ++itr) { cout << 't' << itr->first << 't' << itr->second << 'n'; } return 0; }
main() Function in C++
A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.
Syntax for main() Function in C++
void main() { ............ ............ }
void
void is a keyword in C++ language, void means nothing, whenever we use void as a function return type then that function nothing return. here main() function no return any value.
main
main is a name of function which is predefined function in C++ library. In place of void we can also use int return type of main() function, at that time main() return integer type value. 1) It cannot be used anywhere in the program a) in particular, it cannot be called recursively b) its address cannot be taken 2) It cannot be predefined and cannot be overloaded: effectively, the name main in the global namespace is reserved for functions (although it can be used to name classes, namespaces, enumerations, and any entity in a non-global namespace, except that a function called "main" cannot be declared with C language linkage in any namespace). 3) It cannot be defined as deleted or (since C++11) declared with C language linkage, constexpr (since C++11), consteval (since C++20), inline, or static. 4) The body of the main function does not need to contain the return statement: if control reaches the end of main without encountering a return statement, the effect is that of executing return 0;. 5) Execution of the return (or the implicit return upon reaching the end of main) is equivalent to first leaving the function normally (which destroys the objects with automatic storage duration) and then calling std::exit with the same argument as the argument of the return. (std::exit then destroys static objects and terminates the program). 6) (since C++14) The return type of the main function cannot be deduced (auto main() {... is not allowed). 7) (since C++20) The main function cannot be a coroutine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/* simple code example by main() function in C++ */ #include <iostream> using namespace std; int main() { int day = 4; switch (day) { case 1: cout << "Monday"; break; case 2: cout << "Tuesday"; break; case 3: cout << "Wednesday"; break; case 4: cout << "Thursday"; break; case 5: cout << "Friday"; break; case 6: cout << "Saturday"; break; case 7: cout << "Sunday"; break; } return 0; }
Namespaces in C++ Language
Consider a situation, when we have two persons with the same name, jhon, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother's or father's name, etc. Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function you are referring to within your code. A namespace is designed to overcome this difficulty and is used as additional information to differentiate similar functions, classes, variables etc. with the same name available in different libraries. Using namespace, you can define the context in which names are defined. In essence, a namespace defines a scope.
Defining a Namespace
A namespace definition begins with the keyword namespace followed by the namespace name as follows:
namespace namespace_name { // code declarations }
To call the namespace-enabled version of either function or variable, prepend (::) the namespace name as follows:
name::code; // code could be variable or function.
Using Directive
You can also avoid prepending of namespaces with the using namespace directive. This directive tells the compiler that the subsequent code is making use of names in the specified namespace.
Discontiguous Namespaces
A namespace can be defined in several parts and so a namespace is made up of the sum of its separately defined parts. The separate parts of a namespace can be spread over multiple files. So, if one part of the namespace requires a name defined in another file, that name must still be declared. Writing a following namespace definition either defines a new namespace or adds new elements to an existing one:
namespace namespace_name { // code declarations }
Nested Namespaces
Namespaces can be nested where you can define one namespace inside another name space as follows:
namespace namespace_name1 { // code declarations namespace namespace_name2 { // code declarations } }
• Namespace is a feature added in C++ and not present in C. • A namespace is a declarative region that provides a scope to the identifiers (names of the types, function, variables etc) inside it. • Multiple namespace blocks with the same name are allowed. All declarations within those blocks are declared in the named scope. • Namespace declarations appear only at global scope. • Namespace declarations can be nested within another namespace. • Namespace declarations don't have access specifiers. (Public or private) • No need to give semicolon after the closing brace of definition of namespace. • We can split the definition of namespace over several units.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/* namespaces in C++ language */ // A C++ code to demonstrate that we can define // methods outside namespace. #include <iostream> using namespace std; // Creating a namespace namespace ns { void display(); class happy { public: void display(); }; } // Defining methods of namespace void ns::happy::display() { cout << "ns::happy::display()\n"; } void ns::display() { cout << "ns::display()\n"; } // Driver code int main() { ns::happy obj; ns::display(); obj.display(); return 0; }
Map Library operator[] Index in C++
Access element. If k matches the key of an element in the container, the function returns a reference to its mapped value. This operator is used to reference the element present at position given inside the operator. It is similar to the at() function, the only difference is that the at() function throws an out-of-range exception when the position is not in the bounds of the size of map, while this operator causes undefined behavior. If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value. Notice that this always increases the container size by one, even if no mapped value is assigned to the element (the element is constructed using its default constructor). A similar member function, map::at, has the same behavior when an element with the key exists, but throws an exception when it does not.
Syntax for Map operator[] Index in C++
#include <map> mapped_type& operator[] (const key_type& k); mapped_type& operator[] (key_type&& k);
k
Key value of the element whose mapped value is accessed. Member type key_type is the type of the keys for the elements stored in the container, defined in map as an alias of its first template parameter (Key). If an rvalue (second version), the key is moved instead of copied when a new element is inserted. Function returns a reference to the mapped value of the element with a key value equivalent to k. Member type mapped_type is the type of the mapped values in the container, defined in map as an alias of its second template parameter (T).
Complexity
Logarithmic in size
Iterator validity
No changes
Data races
The container is accessed, and potentially modified. The function accesses an element and returns a reference that can be used to modify its mapped value. Concurrently accessing other elements is safe. If the function inserts a new element, concurrently iterating ranges in the container is not safe.
Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the container. If a new element is inserted and allocator_traits::construct cannot construct an element with k and a default-constructed mapped_type (or if mapped_type is not default constructible), it causes undefined behavior.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/* map::operator[] is a reference operator. This operator is used to access the element in the container by its key. If there is no key matching in the container, then the operator inserts a new element with that key and returns the reference of the mapped value. This operator works the same as the map::at(), the only difference is that at() throws an exception when the key is not present in the map container. */ /* Access element by map::operator[] code example */ #include <map> #include <iostream> #include<string> using namespace std; int main() { // map declaration map<int,string> mymap; // mapping integers to strings mymap[1] = "Hi"; mymap[2] = "Coders"; mymap[3] = "8)"; mymap[4] = "Happy Codings"; // using operator[] to print string // mapped to integer 4 cout << mymap[4]; return 0; }
#include Directive in C++
#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.
Syntax for #include Directive in C++
#include "user-defined_file"
Including using " ": When using the double quotes(" "), the preprocessor access the current directory in which the source "header_file" is located. This type is mainly used to access any header files of the user's program or user-defined files.
#include <header_file>
Including using <>: While importing file using angular brackets(<>), the the preprocessor uses a predetermined directory path to access the file. It is mainly used to access system header files located in the standard system directories. Header File or Standard files: This is a file which contains C/C++ function declarations and macro definitions to be shared between several source files. Functions like the printf(), scanf(), cout, cin and various other input-output or other standard functions are contained within different header files. So to utilise those functions, the users need to import a few header files which define the required functions. User-defined files: These files resembles the header files, except for the fact that they are written and defined by the user itself. This saves the user from writing a particular function multiple times. Once a user-defined file is written, it can be imported anywhere in the program using the #include preprocessor. • In #include directive, comments are not recognized. So in case of #include <a//b>, a//b is treated as filename. • In #include directive, backslash is considered as normal text not escape sequence. So in case of #include <a\nb>, a\nb is treated as filename. • You can use only comment after filename otherwise it will give error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* using #include directive in C language */ #include <stdio.h> int main() { /* * C standard library printf function * defined in the stdio.h header file */ printf("I love you Clementine"); printf("I love you so much"); printf("HappyCodings"); return 0; }


Enter the array size and array elements, now start finding for the "smallest element" in the array to display the smallest element of the array as shown here in C++ sample program.
In C++, This category of the operators is used to compare different values. The result of the operation is a Boolean value. The "Relational" operators are used in the form Operand1 and