A logical statement is one that will return a boolean or a logical "True" or "False" output. It is used in cases where conditions need to be executed.
For ex: lets say you write a system that checks the age of the visitors to a bar, the system should only allow people who are over 18 yrs of age. So the logical condition will be like below:
if(age > 18) then "Let the Customer Enter"
else "The customer is a minor, send them back to stay out of trouble"
What are the 5 Latin languages?
There are 47 Romance Languages, according to Ethnologue. The most common are:
Romanian, Portuguese, Spanish, French, Italian, Catalán, and an appreciable segment of English.
For a complete list, see related links.
How do you find most occurring digit in a number?
Count them unless the number has a recurring ending.
What is function of GOSUB statement in subrouteen?
in BASIC, GOSUB and the RETURN statement allows the use of subrouteens.
Would majoring in International Business and minoring in Computer Science be a good idea?
All the knowledge can get are good. However, whats more important your goals, you have to know that some of the colleges offer both under the same degree plan. get more for your money.
What is the difference between reference variable and painter variable?
Reference Variable
Pointer Variable
Why are the indents necessary after the if and else statement?
Indents are not necessary for simple if statements:
if (true) /* do something */ ;
else /* do something */;
However, when a statement is a compound statement, it's best to place the statement body on a separate line and indent it:
if (true) {
/* do something */ ; /* do something */ ; /* do something */ ;
} else {
/* do something */;
/* do something */;
}
The indents help the reader; separating the controlling expressions from the compound statements and thus exposing the structure of the if statement itself.
C compiler for 64bit computer?
Platform-dependent (Windows, Linux, AIX, MacOs etx), but gcc seems to be a safe bet.
What is the logic for random number generator in C programming?
There are many different ways of generating pseudo random numbers. Some of them are good. Some of them are not so good. It depends on the application. For a good read on this topic, I suggest "The Art Of Computer Programming", Donald E. Knuth, Volume 2, Seminumerical Algorithms.
One of the simpler way of generating pseudo random numbers is the linear congruential generator, wherein XN+1 = (AXN + B) mod C. Of course, the choice of A, B, and C is crucial to a successful implementation. Knuth has a lot to say about this generator, including the fact that it is sequentially correlated and, thus, not well suited for some applications. Nevertheless, many random number generators use this method, and they use some techniques for minimizing correlation and maximizing period. The technique used in one of the Microsoft Visual Studio runtime libraries has A=0x343FD, B=0x269EC3, and C=0x100000000, however, the return value is the value of X right shifted 16 places and AND'ed with 0x7FFF, forcing a return value between 0 and 32767, but a period much larger than that.
int rand(unsigned *seed) { /* assumes unsigned is 32 bits */
*seed = *seed * 0x343FD + 0x269EC3;
return (*seed >> 16) & 32767;
}
Do all elements in a multidimensional array have the same data type?
That really depends on the programming language. In Java, the answer is basically "yes", although if you choose the "Object" data type you could probably accomodate different data types.
If you need collections of different data types - again, assuming Java - it is probably better to use some other structures, for better organization. For example, you can organize different data types into an object. Then you can collect various of those in an array. As an example, you can create an array of objects of a class "Person"; and you this class so that each Person has an age (type int), a name (type String), and any other information you need for your specific application.
Why is pseudo code called false code?
Pseudo code cannot be processed by a machine, it is solely intended for processing by humans.
To count the number of characters in the given text file in unix?
Look at the "wc" command's man page, it will give you a count of all characters, including the newline character.
Example of lazy copy in c plus plus?
Lazy copying is a hybrid of the standard shallow-copy and deep-copy mechanisms. Objects that are copy constructed or assigned from existing instances will initially be shallow-copied, meaning their dynamic data members will share the same memory. When an object is mutated whilst sharing memory, its data will be deep copied so as not to affect the shared instances.
In other words, deep-copying is postponed until it is actually required (if at all). For large and complex objects, this can offer a significant memory saving and a major performance boost as a shallow copy is significantly faster than a deep copy, and sharing memory obviously consumes less memory.
In order to implement lazy copying, it is necessary for each instance to be fully aware of all the instances it shares memory with. One of the simplest ways of achieving that is for each instance to maintain bi-directional pointers, similar to those you would find in a doubly-linked list. However, unlike a linked list, there is no need to expose these pointers outside of the class as the class can link and unlink all by itself, via the copy constructor and the assignment operator. All the functionality is encapsulated within the class so the lazy copy mechanism is completely transparent to the end user.
The following implementation provides a brief demonstration of how the mechanism works. It is by no means a complete implementation as it can only handle one type of data, but it serves to demonstrate the key aspects of lazy copying. A more complete implementation would change the data to a template class, thus allowing any type of data to be lazy copied.
The output shows that while each instance of the object occupies separate memory locations, the data they contain is initially shared. We then manipulate the objects to show that deep copying is occurring when it is required, and that destroying a share doesn't affect any remaining shares. If you strip away the trace code in the main function you will see that the lazy copy mechanism is completely transparent; you need never know it exists as it is fully encapsulated within the Object class itself.
// Demonstration of a lazy copy mechanism
// Copyright ©PCForrest, 2012
#include <iostream>
using namespace std;
// Example data container.
class Data
{
friend ostream& operator<<(ostream& os, const Data& data);
public:
inline ~Data(){delete(m_num);}
inline Data():m_num(new int(0)){}
inline Data(const int num):m_num(new int(num)){}
inline Data(const Data& data):m_num(new int(*data.m_num)){}
inline Data& operator=(const Data& data){*m_num=*data.m_num; return(*this);}
inline Data& operator=(const int num){*m_num=num; return(*this);}
inline bool operator==(const Data& data){return(*m_num==*data.m_num);}
inline bool operator!=(const Data& data){return(*m_num!=*data.m_num);}
inline int operator+(const Data& data){return(*m_num+*data.m_num);}
inline int operator+(const int num){return(*m_num+num);}
inline Data& operator+=(const Data& data){*m_num+=*data.m_num; return(*this);}
inline Data& operator+=(const int num){*m_num+=num; return(*this);}
inline int GetNum()const{return(*m_num);}
inline void SetNum(const int num){*m_num=num;}
private:
int * m_num;
};
// Friend function
ostream& operator<<(ostream& os, const Data& data)
{
os<<"Data:0x"<<&data<<" ("<<*data.m_num<<")";
return(os);
}
// Lazy copy class.
class Object
{
friend ostream& operator<<(ostream& os, const Object& object);
public:
inline Object():m_nextshare(NULL),m_prevshare(NULL),m_data(new Data(0)){}
inline Object(const Object& object):m_prevshare(&object.LocateLastShare()),m_nextshare(NULL),m_data(object.m_data){m_prevshare->m_nextshare=this;}
inline ~Object(){if(IsShared())UnlinkShare();else delete( m_data ); m_data = NULL;}
Object& operator=(const Object& object);
Object& operator+=(const Object& object);
inline Data GetData()const{return( *m_data);}
void SetData(const Data& data);
private:
inline bool IsShared()const{return(m_prevshare!=NULL m_nextshare!=NULL);}
Object& LocateLastShare()const;
Object* LocateShare(const Object & object)const;
void UnlinkShare();
mutable Object * m_nextshare;
mutable Object * m_prevshare;
Data * m_data;
};
// Friend function
ostream& operator<<(ostream& os, const Object& object)
{
os<<"Object:0x"<<&object<<"\t"<<*object.m_data;
return(os);
}
// Assign (implements shallow-copy)
Object& Object::operator=(const Object& object)
{
if( &object != this && // Not a self-reference.
!LocateShare(object) ) // Not already shared.
{
// Unlink or destroy data.
if( IsShared() )
UnlinkShare();
else if( m_data )
delete( m_data );
// Shallow-copy.
m_data = object.m_data;
// Link to new shares.
m_prevshare = &object.LocateLastShare();
m_prevshare->m_nextshare = this;
}
return(*this);
}
// Add/assign (implements deep-copy)
Object& Object::operator+=(const Object& object)
{
if( IsShared() )
{
UnlinkShare();
m_data = new Data( *m_data + *object.m_data );
}
else
*m_data += *object.m_data;
return( *this );
}
// Returns a reference to the last shared instance of this instance.
Object& Object::LocateLastShare()const
{
Object* p=(Object*)this;
while(p && p->m_nextshare)
p=p->m_nextshare;
return(*p);
}
// Returns a pointer to the given object if it is amongst the shared instances
// of this instance. Returns NULL if the object is this instance or is not shared.
Object* Object::LocateShare(const Object& object)const
{
// Search previous instances first.
Object* p=m_prevshare;
while( p && p!=&object)
p=p->m_prevshare;
if(!p)
{
// Not found, search next instances:
p = m_nextshare;
while( p && p!=&object) p=p->m_nextshare;
}
return(p);
}
// Unlinks this object from its shared instances.
void Object::UnlinkShare()
{
// Update the links on either side first.
if(m_nextshare) m_nextshare->m_prevshare=m_prevshare;
if(m_prevshare) m_prevshare->m_nextshare=m_nextshare;
m_nextshare=NULL;
m_prevshare=NULL;
}
// Mutator. Implements deep copy if incoming data differs.
void Object::SetData(const Data& data)
{
if( *m_data != data )
{
if( IsShared() )
{
UnlinkShare();
m_data = new Data(data);
}
else
*m_data = data;
}
}
// Demonstration program:
int main()
{
Object a;
a.SetData( 5 );
Object b = a; // Assign (lazy copy)
Object* c = new Object(b); // Copy construct (lazy copy)
cout<<"Original memory:"<<endl;
cout<<"a\t"<<a<<endl;
cout<<"b\t"<<b<<endl;
cout<<"c\t"<<*c<<endl;
cout<<endl;
b += a; // Deep copy.
cout<<"After mutating b:"<<endl;
cout<<"a\t"<<a<<endl;
cout<<"b\t"<<b<<endl;
cout<<"c\t"<<*c<<endl;
cout<<endl;
delete(c);
cout<<"After destroying c:"<<endl;
cout<<"a\t"<<a<<endl;
cout<<"b\t"<<b<<endl;
cout<<endl;
// Instantiate a new, unshared instance
c = new Object();
cout<<"After instantiating c as new:"<<endl;
cout<<"a\t"<<a<<endl;
cout<<"b\t"<<b<<endl;
cout<<"c\t"<<*c<<endl;
cout<<endl;
// Assign b to c
*c = b;
cout<<"After reassigning c:"<<endl;
cout<<"a\t"<<a<<endl;
cout<<"b\t"<<b<<endl;
cout<<"c\t"<<*c<<endl;
cout<<endl;
return(0);
}
Output:
Original memory:
a Object:0x001FFA20 Data:0x003577B8 (5)
b Object:0x001FFA0C Data:0x003577B8 (5)
c Object:0x00211F58 Data:0x003577B8 (5)
After mutating b:
a Object:0x001FFA20 Data:0x003577B8 (5)
b Object:0x001FFA0C Data:0x00357818 (10)
c Object:0x00211F58 Data:0x003577B8 (5)
After destroying c:
a Object:0x001FFA20 Data:0x003577B8 (5)
b Object:0x001FFA0C Data:0x00357818 (10)
After instantiating c as new:
a Object:0x001FFA20 Data:0x003577B8 (5)
b Object:0x001FFA0C Data:0x00357818 (10)
c Object:0x00211F58 Data:0x003578A8 (0)
After reassigning c:
a Object:0x001FFA20 Data:0x003577B8 (5)
b Object:0x001FFA0C Data:0x00357818 (10)
c Object:0x00211F58 Data:0x00357818 (10)
The operators are &&, &, |, . IF function does not exist in C language. C has if-statements
struct student
{
nt regno,mark[4],avg;
char name[10];
};
void main()
{
student s[100];
int i,j,t=0;
printf("enter student DETAILES\n");
for(i=0;i<100;i++)
{
printf("ENTER REGISTER NO : ");
scanf("%d",&s[i].regno);
printf("ENTER NAME : ");
scanf("%s",s[i].name);
printf("ENTER FOUR MARKS \n");
s[i].avg=0;
for(j=0;j<4;j++)
{
scanf("%d",&s[i].mark[j]);
t=t+s[i].mark[j];
}
s[i].avg=t/100;
}
printf("THE STUDENTS INFORMATION \N");
for(i=0;i<100;i++)
{
printf("\n REGISTER NUMBER : %d",s[i].regno);
printf("\n NAME : %s",s[i].name);
printf("\n AVERAGE MARK : %d",s[i].avg);
}
getch();
}
Example of relational statements in C programming?
You mean relational operators?
if (argc<1) puts ("No params");
Using C programming language design a menu driven programme that will draw a straight line?
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,opt;
printf("Enter your choice\n");
printf("1. Horizontal line");
printf("\n2. Vertical line\n");
scanf("%d",&opt);
if(opt==1)
{
for(i=0;i<=50;i++)
printf("%c",196);
}
else
{
for(i=0;i<=40;i++)
printf("%c\n",179);
}
return 0;
}
What is a type of spam that collects data from a user without his knowledge?
Spyware is a software that collects information from the user without their knowledge. It also called spybot or tracking software if it is obtained from the internet. Many of these software get automatically installed into the computer as a virus software or as a result of downloading materials from untrusted sources. They may also be installed when some of the deceptive add pop-ups on the internet are clicked.
H-series engine mated with a B-series transmission using an adaptor plate.