Trending February 2024 # Working Of Long Data Type In C++ With Examples # Suggested March 2024 # Top 10 Popular

You are reading the article Working Of Long Data Type In C++ With Examples updated in February 2024 on the website Cancandonuts.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Working Of Long Data Type In C++ With Examples

Introduction to C++ long

Web development, programming languages, Software testing & others

Working of long Data Type in C++

In this article, we will discuss the long data type in C++. The long data type is a basic numerical signed and unsigned integer type which is used for specifying the storage size and location of variables or constants that are used in programs that can hold values as long as a single 64-bit signed (numbers can be either positive or negative) integer type or unsigned (only positive numbers) integer type that is long can store 263 with one bit for the sign. This long type is used to store large values that are equivalent to the long int type. These long type variables can be used with double variables also as it can be used as a long int. In C++ there is also another data type where it can help us store numbers larger than long and such variables can be stored with data type long long which is created twice using long data type but this long long type modifier can only be used with the int data type. In C++, there are specific literals provided to these data types such as for long type we use either “L” or “l” is used to identify long literal by suffixing these alphabets and for long long int we suffix with “LL” literal which are used for signed and if we want to indicate unsigned long then suffix wit “UL” and unsigned long long int then we have to suffix with “ULL”.

Examples of C++ long

Now in the below section let us see how to declare long variables in a program.

Example #1

Code:

using namespace std; int main() { long a = 4564667; long int b = 4564667; cout <<“Program to demonstrate long in C++” <<“n”<<endl; cout <<“The value of variable with long variable a is  “<< a <<“n”<< endl; cout <<“The value of variable with log int variable b is “<< b << “n”<<endl; cout <<“The size of long variable a is ” << sizeof(a) <<“n” << endl; cout <<“The size of long int variable b is “<< sizeof(b) <<“n” <<endl; return 0; }

Output:

In the above program, we can see we have created a variable with long type “a” and another variable “b” with long int type these both have the same value so we can say long long and long int type is the same and we also can see we are declaring the size of the variables which can be done using sizeof() function. So we can say the size of long and long int have the same size that is 8.

Example #2

Code:

using namespace std; int main () { long p, q; long long res; p = 5456943859; q = 254689; res = p * q; cout<<“Program to demonstrate long long type in C++” <<“n”<<endl; cout<<“The long type varaibles p ” << p << ” and q ” <<q << “is n”<<endl; cout <<“The product of two long variables p*q = “<< res <<endl;; cout<< sizeof(res)<<endl; return 0; }

Output:

In the above program, we can see we have declared two long variables p and q and we are trying to find the product of these two variables which will be a very large value so we are declaring the variable “res” which will be the long long type which can store large value than long type. So in the above screenshot, we can see the output, and also we can see a size of long long variable “res” which prints 8 and the product value is 1389823574504851.

Example #3

Now we will see a sample example of using literals for long unsigned and signed data types.

using namespace std; int main () { long p = -5456943859L; long z = 8647627343UL; long long r = 1389823574504851LL; cout<<“Program to demonstrate long long and long type literals in C++” <<“n”<<endl; cout<<“The long type varaibles p literal is  ” << p <<“n”<<endl; cout<<“The long type variable z literal of unsigned long variable is “<<z <<“n”<<endl; cout<<“The long long type of variable r literal is = “<< r <<endl; return 0; }

Output:

In the above program, we can see we have declared a long variable “p” with value and we have suffixed it with “L” and we have also declared long long type variable “r” and we have suffixed it with “LL”. In the above program, we have seen we have p value suffixed with L as “5456943859L” and r variable which is the long long type with value 1389823574504851LL where we can see p and r are signed long variables. So the variable “z” is also a long type but it is unsigned so it can have only a positive number which can be seen in the above screenshot.

Conclusion

In this article, we can conclude that the long type variable in C++ is a type of data type which is used for storing the values that are as large as 64-bit values, and in C++ it also provides a data type long long which is another data type to store values larger than the long type which means it can hold the value twice of long type. In this article, we have seen a simple example of how to declare the long type variables which is equivalent to long int in C++. In this article, we also saw the example of long long type variables along with the literals which are used by suffixing it with value to indicate the signed or unsigned long type variables.

Recommended Articles

This is a guide to C++ long. Here we also discuss the introduction and working of long data type in c++ along with different examples and its code implementation. You may also have a look at the following articles to learn more –

You're reading Working Of Long Data Type In C++ With Examples

Working Of Jquery Reference In Jquery With Examples

Definition of jQuery Reference

In Jquery, reference is defined as a set provided by jquery which contains jquery events used for triggering methods, selectors, and properties, which are defined for selecting and converting HTML elements provided few methods for handling events for such selections which when the events are triggered when the methods are executed and this jquery reference have the ability where to make the navigation (top, down, right and left) of the HTML elements along with supporting of jquery effects such as sliding or fading or showing or any kind of animations in the web pages using HTML elements are all defined and are provided by the jquery reference in Jquery.

Start Your Free Software Development Course

Working of Reference in jQuery Examples

In the below section let us take one by one element of the jquery reference that contains methods, events, effects, selectors, utilities, etc along with examples:

Events Example

Code:

#circle { width: 150px; height: 150px; border-radius: 50%; background-color: green; margin: 200px 200px 200px 200px; } });

Output:

jQuery Reference manipulation methods Example

Code:

$(document).ready(function () { $(‘p’).append(‘Educba ‘); }); div{ border: 2px solid; background-color:blue; margin: 5px 0 5px 0; font-size:20px; }

Output:

In the above program, we can see we are using append(), prepend(), after(), and before() method where we have added the content after the h1 element which shown in cyan color, then we are adding content before second div tag which is shown in yellow color, then we add the content at beginning of the paragraph which gives prepended paragraph and then the paragraph content is appended with the word “Educba” and prints complete sentence “Welcome to Educba”. There are many such methods used for constructing such web pages.

Selectors

In jquery, it provides the main function which is used only when we are using jquery codes as we know before writing jquery code we start with $ symbol so this is called as factory function which has the syntax as “$()” where we can pass any name or element name, id, class, etc of tags that are defined in the HTML structure.

Example

Code:

<script type = “text/javascript” #circle { width: 150px; height: 150px; border-radius: 50%; background-color: green; margin: 10px; } .educbaclass { margin:50px; border :10px solid; } }); $(“p”).css(“background-color”, “yellow”);

In the above program, we can see we have declared a div tag and defined with id name as “circle” so we are using the selector on div tags which has id. Similarly, we have also defined a class name for paragraph “p” and we can see in the above code we are printing that selected paragraph with different CSS styles which can be done not only by the CSS syntax in HTML structure but also using jquery selector and function CSS() on paragraph tag. Therefore there are many such selectors that are used in jquery reference such as selecting multiple elements, selecting all the elements of DOM using universal selector, etc.

In jquery reference, there are effects which are used for animation effects in web pages such as animate(), fadIn(), fadeout(), hide(), show(), etc. In traversing reference can be used for movement of elements such as up, down, right, left, etc.

Conclusion Recommended Articles

This is a guide to jQuery Reference. Here we also discuss the Definition and Working of jQuery Reference in jQuery with Examples along with different examples and its code implementation. You may also have a look at the following articles to learn more –

Examples Of The Operator=() Function In C++

Introduction to C++ operator=()

Web development, programming languages, Software testing & others

So when the assignment operator is overloaded, the assignment operator should be performed on the user-defined data types as well, so all values of one object (user-defined data types) can be copied to another object.

Syntax 

Below is the syntax mentioned:

return_type : : operator =(Parameter_list ) { }

An operator is an operator function where the operator is a keyword that will be there for all operators overload and = is an assignment operator being overloaded.

Working and Examples of the Operator=() function in C++

Next, we write the C++ code to understand the Operator=() function working more clearly with the following example where we use Operator=() function to copy one object to another object, as below –

Example #1

Code:

using namespace std; class Employee { public: int salary; Employee( int sal ) { salary = sal; } Employee operator =(Employee n) { Employee temp = n.salary; return temp; } }; int main() { Employee e1( 20000 ); Employee e2( 25000 ); Employee e3 = e1; cout<< e3.salary; return 0; }

Output:

As in the above code, the Employee operator =(Employee n ); function is defined for an assignment operator overload, as here this function accepted the Employee class object as a parameter, and it returns accepted object salary that is what assign or copy to another object when used assignment operator as in code Employee e3 = e1; Once compiler encounter e3 = e1; statement it calls to the operator =(Employee n ); defined function as e3.operator =(e1). Here e1 object is passed as a parameter, and e3 is the object on which the assignment operator function is called, so e1.salary is assigned or copied to the e3 object.

Next, we rewrite the above C++ code to see what happens if we do not define the Operator =() function in class to copy one object to another object, as below –

Example #2

using namespace std; class Employee { public: int salary; Employee( int sal ) { salary = sal; } }; int main() { Employee e1( 20000 ); Employee e2( 25000 ); Employee e3 = e1; cout<< e3.salary; return 0; }

Output:

As in the above code the Employee operator =(Employee n); function is not defined for an assignment operator to be overloaded, but object e1 is copied to e3 as we got the same output 20000. So the assignment operator is overloaded for user-defined objects, whereas other binary operators, by default not overloaded like ‘+,’ ‘-, ‘‘*’ etc.

Next, we rewrite the above c++ code to see what happens if we do not define the Operator +() function in class to perform the addition of object, as below –

Example #3

Code:

using namespace std; class Employee { public: int salary; Employee( int sal ) { salary = sal; } }; int main() { Employee e1( 20000 ); Employee e2( 25000 ); Employee e3 = e1 + e2; cout<< e3.salary; return 0; }

Once we compile the above code we get the below error –

Next, we rewrite the above C++ code to overload the Operator=() function where it copies one object to another object with some operation, as below –

Example #4

Code:

using namespace std; class Employee { public: int salary; Employee( int sal ) { salary = sal; } void operator =(Employee n) { salary = n.salary + 10000; } }; int main() { Employee e1( 20000 ); Employee e2( 25000 ); e2 = e1; cout<< e2.salary; return 0; }

Output:

As in the above code, the Employee operator =(Employee n); function is defined for an assignment operator overload, as here this function accepts the Employee class object as a parameter, and it updates the salary of the calling object by the salary of the passed object with the addition of 1000. So when an assignment operator is used as in the above code, Employee e3 = e1; the e3 salary is updated or copied by e1 object salary plus 10000. Therefore the output is 30000, not just 20000.

Conclusion

Operator=( ) overload an assignment Operator in C++, which can be used to redefine the assignment operators to perform the operation on the user-defined data type.

Recommended Articles

This is a guide to C++ operator=(). Here we have discussed the introduction to Operator=() function in C++ and the programming examples. You may also have a look at the following articles to learn more –

How Boolean Type Works In Perl With Examples

Introduction to Perl boolean

Perl boolean type is a type of value that, unlike other programming languages, behaves differently in a manner where the function using these values returns true or false. Perl programming language is not considered conventional when it comes for making the value as true or false. These values are used only for interpretation and significance that these are boolean values, not the actual values for manipulation. A boolean value is not majorly used in Perl language; rather, it is used only when the typical systems have made use of these as return types for identification and manipulation.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

use boolean; do &always if true_val; do &never if false_val;

The module as boolean makes use of basic as data type which is used for making the entire system comprising f values which is true or false depending on the value.

How boolean Type Works in Perl?

There are many ways to represent the boolean values in Perl for which the programmer depends or work for with the help of making the process of evaluating the conditional checking, system checking and many other factors which depends on the boolean type of Perl. These values are not any kind of special values that need to have value as true or false. On the other hand, there are a number of ways in which the value is being taken care of in terms of boolean.

There are some values that are always false in the Perl programming language, namely, ‘undef’, 0, 0.0, ‘’, ‘0’.

Boolean for Perl programming language uses other scalar values but not the naïve values like other programming languages.

Boolean in Perl can be of many types, like if in case the value comes out to be truth, then it needs conversion into the value as false depending on the type of requirement at the time of implementation.

Most often, the values come out to be false, but within that value of return, there might be some inbuild system variables which internally gets a comparison with the values and returns the value as true within it, which is mentioned in an example further.

There are times when boolean is used for undef and empty string; then, in that case, it is very much needed to make the entire set of boolean justifiable with the other values that need conversion and worthy for representation.

Using Strict and warnings for the values and the programs in execution is quite useful whenever needed to get the troubleshooting done correctly.

Strict and warning usage with the empty string in consideration sometimes provides the warning for any Perl program into execution. Also, it helps in making the overall result to be moved in some streamlined way.

There are some values as 0, which is true in some or the other way where the boolean values are text in the form of string and then when it is used, it gets converted into some type of number converted into some value with string.

There are some of the values which are considered as truth with respect to the usage of the unary operator and can be converted into a lie when used with a single operator; other than that, when double unary operator !! is used, it will be used for converting the entire value as a lie.

Examples of Perl boolean

Given below are the examples of Perl boolean:

Example #1

This program demonstrates the use of Perl statement, which is used as a conditional statement to check whether the value taken is true or false depending on the scenario and requirement.

Code:

#!/usr/bin/perl if ('even_no') { print 'true'; } else { print 'false'; }

Output:

Example #2

This program demonstrates the false values for the variable being assigned a value as 0, as shown in the output.

Code:

#!/usr/bin/perl $at_1 = 0; if ($at_1) { print "at_1 is Truen"; } else { print "at_1 is Falsen"; }

Output:

Example #3

This program demonstrates the use of undef with the condition in Perl, which is used for giving the output as shown.

Code:

#!/usr/bin/perl foreach my $vl_3 (undef, 0, 0.5, '', '8') { if ($vl_3) { print "truen"; } else { print "falsen"; } }

Example #4

This program demonstrates the empty string, which is used for checking the condition with the value to be returned as true or false as shown in the output.

Code:

#!/usr/bin/perl $bt_emp = ''; if ($bt_emp) { print "bt_emp is Truen"; } else { print "bt_emp is Falsen"; }

Output:

Example #5

This program is used for demonstrating the values by using warnings or strict as a standard file inclusion for a variable as shown in the output.

Code:

#!/usr/bin/perl use warnings; use strict; my $one_vr = undef; print $one_vr + 2;

Output:

Example #6

There are times when the value as string internally gets converted into the value as 0 and then when compared with the conditional check by evaluation is considered as shown in the output where the string is fed as an input to the value, and then it throws the value as true as shown.

Code:

#!/usr/bin/perl if ('0FR1RG') { print 'true'; } else { print 'false'; }

Output:

Example #7

This program demonstrates the use of unary operator ! which is used for making the value as truth from lie with the canonical format that is often used for manipulation.

Code:

#!/usr/bin/perl use Data::Dumper; print Dumper !!'Welcome_Everyone!';

Output:

Conclusion

Perl boolean is a type of boolean value used for making the Perl language use and identifies the return type by other methods and functions as true or false. Overall, Perl boolean, although not used so much significantly but once used, can solve many problems related to conditional check and evaluation, which programmers most often use.

Recommended Articles

This is a guide to Perl boolean. Here we discuss the introduction, how boolean type works in Perl? Along with examples, respectively. You may also have a look at the following articles to learn more –

Working Of The Jquery Param() With Examples

Introduction to jQuery param()

In jQuery, param() is a function defined as the Ajax method, which is used for representing the continuous string of an object or an array; while making the Ajax request, the URL can use these serialized or continuous string values for calling the request. In general, we can define-param() function as a function for converting to the continuous string from the provided elements internally and if in case any plain object is passed which would properties like name or value that contains the input elements along with these properties and this function has the options to disable globally by setting the traditional value to true.

Start Your Free Software Development Course

Working of the jQuery param() with Examples

In this article, we will see the param() function of jQuery, which is an Ajax method for making the Ajax request; we need to use these serialized string obtained after applying this function to the elements internally, which contain the return value as a continuous string of an array or object. In jQuery, the param() function is used by the URL for making the Ajax request by converting the elements into the continuous string as the output of this param() function, or we can say this function returns the serialized string representation of an array or plain object.

Let us see syntax and examples of how to use this function:

Syntax:

$.param(object, traditional_style)

Parameters:

Object: This parameter is used to specify the string or object that needs to be serialized. This parameter needs to be specified compulsory.

Traditional: This parameter is used to specify the serialization styles of param() function that is required to use or not the traditional shallow style, which is a Boolean value to be specified, and this parameter is optional.

This function returns the converted serialized string representation of an array or an object that is passed to this function.

Let us consider an example of how to declare the param() function.

Example #1

Code:

Educba Training Institute <script src= EDUCBA Jquery $(document).ready(function() { jqpmobj = new Object(); jqpmobj.Fullword = “EDUCBA “; jqpmobj.Firstword = “Jquery “; jqpmobj.Secondword = “Param() “; jqpmobj.Thirdword = “Function “; jqpmobj.Wordcolor = “Blue”; $(“div”).text($.param(jqpmobj)); }); });

Output:

In the output, we can see each word is separated by “%20&” because we are specifying both for Fullwords and single word spaces are replaced by this in the above output. So in the above code, we have passed the object “jqpmobj”, so we must specify any name or value properties, and here it is “Fullword” or “Firstword”, etc. So this param() function when objects are passed these names or values parameters are added to the URL string, which is dynamically modified with the history API.

Now we will see an example with creating three objects and to display the decoded object, which is done using decodeURIComponent() in the below code.

Example #2

$(document).ready(function() { var com_obj1= new Object ({ p: [ 7, 1, 6 ] }); var com_obj2= new Object ({ p: { q: 7, r: 1, s: 6}, t: [ 3, 9] }); var com_obj3 = new Object({ p: {u: 4, v: 4}, w:[2, 8] }); var x = decodeURIComponent( $.param(com_obj1)); $(“#p1”).text(x); var y = decodeURIComponent( $.param(com_obj2)); $(“#p2”).text(y); var z = decodeURIComponent( $.param(com_obj3)); $(“#p3”).text(z); }); });

Output:

In the above code, we can see we are using the decoseURIComponent(), which is used for decoding the objects so which is a bit complex so; in the above code also we can see we are creating 3 objects and the decoded codes are as shown in the above screenshot of the output.

Conclusion

In this article, we conclude that the jQuery provides a function called param(), which is used for representing the array of objects in a serialized way. In this article, we saw how to declare and use the param() function with syntax and examples. In this article, we also saw an example with the simple creation of the object, and then in another example, we also saw the creation of complex objects and decoding the objects using param() and decodeURIComponent() function.

Recommended Articles

This is a guide to jQuery param(). Here we discuss the introduction and working of the jQuery param() with examples, respectively. You may also have a look at the following articles to learn more –

Top Examples To Implement Of Datareader C#

Introduction to DataReader C#

A Data reader is an object that is used to read data from the data sources. This can only perform read operation and not update operation on the data source. The data is retrieved as a data stream from the data source. Though the data reader is restricted in terms of only reading operation, it is highly effective and optimized as it is read only and forward only. There are two types of providers in the .Net Framework, they are SQLDataReader and OleDbDataReader. The data reader increases the application performance by reducing system overhead as it stores the only row in memory at a given point of time. This article will cover in detail the data reader in c# along with appropriate examples.

Start Your Free Software Development Course

Syntax:

The sql data reader is available in the namespace System.Data.SqlClient and the corresponding assembly is chúng tôi A SQL data reader is initialized as follows.

SqlDataReadersqlReader = sqlCmd.ExecuteReader();

The execute reader is used to pass the SQL statements or procedure to the sqlconnection object and the corresponding result is stored in the sqlreader object of SqlDataReader. Before reading from any data reader, it should always be open and should point to the first record. The read() method of data reader is used to read and it moves forward to the next row.

The oledb data reader also behaves in the same way. It is available in the name space System.Data.OleDb and the corresponding assembly is chúng tôi An oledbDataReader object is used to connect to OLEDB data sources and fetch data from them. Like SQLDataReader, oledbdata reader should also be open before performing read operation. An oledb data reader is initialized as follows.

OleDbDataReaderoledbReader = oledbCmd.ExecuteReader();

Where the executereader is used to carry out the SQL statements or procedures.

Accessing Data Reader Results Working with Multiple Sets

If data reader returns multiple result sets, the NextResult method of data reader can be used to access them. During implementation, it should be noted and taken care that all the result sets are being iterated and each column inside the result set is accessible.

Examples to Implement of DataReader C#

Below are the examples of DataReader C#:

Example #1

Typically, data is read from the result set returned by the data reader is to iterate each row using a while loop. The read method return value is of bool type, if the next row is present then true is returned and for the last record, false is returned. The while loop will be executed until the condition becomes false.

Syntax:

while(rdr.Read()) { }

Like closing a SQL connection, it is always a best practice to close the Data reader. All the while part can be in enclosed in a try block and the data reader connection can be closed in the finally block.

Syntax:

try { } Catch { } finally { if (reader != null) { reader.Close(); } }

Code:

using System; using System.Windows.Forms; using System.Data.SqlClient; namespace test { public partial class test1 : Form { public test1() { InitializeComponent(); } Public static void main() { string constr = null; SqlConnectionscon ; SqlCommandscmd ; string sstat = null; constr = "Data Source=testserver;Initial Catalog=testdb;User ID=test;Password=test"; sstat = "Select * from test"; scon = new SqlConnection(constr); try { scon.Open(); scmd = new SqlCommand(sstat, scon); SqlDataReadersstatReader = scmd.ExecuteReader(); while (sstatReader.Read()) { Console.WriteLine("Name:" sstatReader.GetValue(0)  + "age:"  sstatReader.GetValue(1) ); } sstatReader.Close(); scmd.Dispose(); scon.Close(); } catch (Exception ex) { } } } }

Example #2

Code:

using System; using System.Windows.Forms; using System.Data.OleDb; namespace test { public partial class test : Form { public test() { InitializeComponent(); } Public static void main() { string constr = null; OleDbConnectionocon ; OleDbCommandocmd ; string sql = null; constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb"; sql = "select * from emp"; ocon = new OleDbConnection(constr); try { ocon.Open(); ocmd = new OleDbCommand(sql, ocon); OleDbDataReaderordr = ocmd.ExecuteReader(); while (ordr.Read ()) { Console.WriteLine("EmpName:" ordr.GetValue(0) + "Empage:"  ordr.GetValue(1) + "Esalary" ordr.GetValue(2) ); } ordr.Close(); ocmd.Dispose(); ocon.Close(); } catch (Exception ex) { Console.WriteLine("Connection Failed"); } } } }

Output:

Conclusion Recommended Article

This is a guide to DataReader C#. Here we discuss the Introduction to DataReader in C# and its examples along with Code Implementation and Output. You can also go through our other suggested articles to learn more –

Update the detailed information about Working Of Long Data Type In C++ With Examples on the Cancandonuts.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!