C# :: New Keyword Not Needed When Doing Reference
Feb 14, 2014
One thing make me consider:
FistClass F1 = new FistClass ();
FistClass F2 = F1;
second line why i dont need to firstly create instance for F2 and then make reference betwwen to classes like:
FistClass F1 = new FistClass ();
FistClass F2 = new FistClass ();
F2 = F1;
View 9 Replies
ADVERTISEMENT
Mar 11, 2012
Below given is the code, which allocates memory for a structure dynamically and stores value in its member. The problem is in the last scanf statement which reads 'ch'. The code will be in infinite loop as it doesnt executes the last scanf statement. The solution for this is (i use this) to add one more similar scanf statement for 'ch' in the very next line. If i do so, it executes the statement, reads 'ch' and then continues.
I want to know why it behaves like that..
struct student{
int usn;
};
int main(){
char ch;
struct student *s;
s=(struct student *)malloc(sizeof(struct student));
[Code] ....
View 11 Replies
View Related
Dec 26, 2014
I know that the null at the end of the string indicates end of that string but why is it actually needed. Strings in C are just arrays of char variables. A "Hello" string would be stored in ascii code as:
char string[] = {72, 101, 108, 108, 111, 0}
When I have array of integers like
int intArray[] = {72, 101, 108, 108, 111}
I can perform various operations with it like comparision with other array etc. but I don't need terminating character
View 6 Replies
View Related
Mar 5, 2013
Write a C++ program to calculate the fewest number of each denomination needed to pay a bill of amount TOTAL. For example, if the end user enters $97 for TOTAL, program will output that the bills would consist of one $50 bill, two $20 bills, one $5 bill, and two $1 bills. (Assume that the amount is in whole dollars, no cents, and only $100, $50, $20, $10, $5, and $1 denominations are available.) Aid: You may want to use the modulus operator %.
View 1 Replies
View Related
Jan 26, 2014
In c# extending the class and implementing an interface is done by : symbol.. But c# has extend keyword. What is the use of extend keyword in c#?
View 8 Replies
View Related
Jun 30, 2014
for starters i hope this question wasn't posted yet.i want to write a small program that askes the user what he wants to do , and then executes the comand in system . But for some reason it doesn't quit on the key word this is the code:
Code:
#include <stdio.h>
/*a simple interaction programme that schow the system options*/
#define systemt "x1b[32m" /*changes the color to green for system output*/
#define user "x1b[0m" /*changes the color to white for user input*/
int main() {
[Code]...
Is there something wrong white the code or does the system bock me from reusing the choise string. i'll inculde the original c file as well
View 1 Replies
View Related
Jan 6, 2014
have a look at the following code :
class Base
{
public:
virtual ~Base()
{
cout << "Calling ~Base()" << endl;
[Code]...
Now this program produces the following result:
Calling ~Derived()
Calling ~Base()
i was reading online and got stuck here. i am unable to understand why 'calling ~Base()' is been printed here? when we reached delete pbase; in int main() it goes to Base class first and finds that its destructor is virtual so it goes to Derive class and finds another destructor and executes it but why does it prints ~Base() in any case?
View 4 Replies
View Related
Feb 19, 2014
How to put virtual keyword in the function of the base class. Will the function still be over-written properly? What will happen if I
(1) call function from base class pointer
(2) call function from derived class pointer
(3) call function from derived class object
If the virtual keyword is present, the over-written version will be called in all cases, am I mistaken?
View 1 Replies
View Related
Sep 24, 2014
I'm trying to read a C code, but there are functions including CLASS word at the titles of functions. Is it a correct implementation?
For example: double CLASS getreal (int type)
What is the meaning of CLASS in titles of functions in C? I could not find such an usage in my C book?
View 6 Replies
View Related
Aug 18, 2014
I was trying to make a tic tac toe game where the user can play against the computer
It s in borland c++ and not in c++ 11 so i wanted to convert it into c++11. My program shows error since there is nothing called conio.h in c++11. Hence I want to know if there is any alternate keyword gor the function getch() so that i could ask the user to press [ENTER].
Code:
#include<process.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
int usbox,i,j,nandu=0,result,cusb,cobox,r,d;
int playl=0;
char copybox[10];
[Code] ....
View 2 Replies
View Related
Apr 13, 2013
how can I make a class non inheritable,,, without using keyword "final" ?
class A
{
//
};
A obj; // No error
class B : public A
{
//
}; // error
View 2 Replies
View Related
Jun 24, 2014
Is the bool keyword in C exactly like the boolean keyword in Java? why this code is getting an 'unknown type error' when I initiialze looping.
#include <stdio.h>
#include <stdlib.h>
int main()
[Code].....
If I am completely using the boolean concept wrong in C, should I just use break statements instead?
View 11 Replies
View Related
Oct 11, 2014
In C++ by FLTK, to define a circle we use some code like this:
Circle c(Point(x,y), r);
And we can using vector_ref put and save them in a vector, like:
Vector_ref<Circle> vc;
vc.push_back(new Circle(Point(x,y),r));
Ok, those were about Circle and no problem till now!
Triangle can be defined like this for using in codes:
Graph_lib::polyline poly;
poly.add(Point(x1,y1),r1);
poly.add(Point(x2,y2),r2);
poly.add(Point(x3,y3),r3);
and this is a vector to saving them:
Vector_ref<Graph_lib::Polygon> vp;
The problem is that how to save/put triangles/polylines into that vp vector using new keyword like the circle does?
My sig: Save Cobani.
View 4 Replies
View Related
Jan 30, 2014
I think there is no always need of keyword extern in order to declare variables globally. Is it right?
For example I can declare a variable globally in one file and use it in some other provided that I have included the last one file ( that has the declaration of the variable of course) and compile these files together :
gcc -c f1.c f2.c for example
View 6 Replies
View Related
Nov 8, 2014
I'm working on a program that reads in a .txt file and searches through the text for a keyword. If it gets a hit on the keyword, the line number where the keyword is located and the line that contains the keyword is printed out. What I have now doesn't catch every occurance of the keyword "a".
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
[Code]......
View 4 Replies
View Related
Apr 25, 2014
I am reading a file whick looks like following:
Code:
10 = NAND(1, 3)
11 = NAND(3, 6, 5)
15 = NAND(9, 6, 2, 8)
Problem: I have to find the word "NAND" and then find the numbers inside the brackets because they are the inputs to that NAND gate. I have written a code below but that code can detect the fixed number of inputs. I need a code which can detect any number of inputs (whether 2 inputs or more than two). But i don't understand how do i do that?
My code:
Code:
string input_str ("INPUT"), output_str ("OUTPUT"), nand_str("NAND");
while (getline( input_file, line ))
{
std::size_t guard_found = line.find(guard_str);
[Code].....
View 8 Replies
View Related
Jan 12, 2013
Im trying to reference my array in another function but i keep getting errors.
void player::store()
{
int menuChoice;
int amountChoice = 0;
int items[4] = {0,0,0,0};
string inv;
[Code]...
errors
C:UsersChayDesktopDinosaur ArenaMainGame.h|81|error: declaration of 'items' as array of references|
C:UsersChayDesktopDinosaur ArenaMainGame.h|81|error: prototype for 'void player::backpack(...)' does not match any in class 'player'|
C:UsersChayDesktopDinosaur Arenaplayer.h|24|error: candidate is: void player::backpack()|
View 4 Replies
View Related
Mar 20, 2013
I tried to answer the question myself and came up with an example.
#include<iostream>
using namespace std;
class A {
public:
int a;
A(int aa) : a(aa) { }
~A() { cout<<"~A()
[code]....
why statements (*) and (**) work ? Since the object a gets destroyed, shouldn't rA be invalid ? Or this is just undefined behavior ?
View 2 Replies
View Related
Aug 2, 2014
Are Reference and Address same or Different?
View 10 Replies
View Related
Nov 25, 2013
(Pass-by-Value vs. Pass-by-Reference)
Write a complete C++ program with the two alternate functions specified below, each of which simply triples the variable count defined in main. Then compare and contrast the two approaches. These two functions are
a) function tripleByValue that passes a copy of count by value, triples the copy and returns the new value and
b) function tripleByReference that passes count by reference via a reference parameter and triples the original value of count through its alias (i.e., the reference parameter).
View 7 Replies
View Related
Apr 10, 2014
I need to pass an array of 10 instances of a custom class to a function. The snippets of code are posted below. How would I do this right?
The prototype:
Code:
int Search(Vertex vertex[], ofstream &outfile);
The implementation in the main function.
Code:
Search(vertex[10], outfile);
View 2 Replies
View Related
Sep 6, 2013
Example code:
Code:
#include <iostream>
#include <vector>
using namespace std;
class A{
[Code]....
I read somewhere, that we can imagine the reference as a pointer to the vector. So, my question is:
Let's assume that instance of class A, named a, was created with new. We call a.getV() to foo and then we call the destructor of a. foo is safe? Is the copy constructor of std::vector called?
View 1 Replies
View Related
Dec 19, 2013
I have in my main(), a function that creates my arg object using boost/program_options.hpp i want to pass this object to another function using templates like this:
Code:
template <typename Targ>
void Count(Targ & arg){
MyObj<string> QueryTab(arg["input-file"].as<string>()); //line number is 352
...
}
However I get an error:
Code:
../include/Filter.hpp: In member function ‘void Count(Targ&)’:
../include/Filter.hpp:352:40: error: expected primary-expression before ‘>’ token
../include/Filter.hpp:352:42: error: expected primary-expression before ‘)’ token
... obviously it does not recognize my intention, what did I do wrong?
View 2 Replies
View Related
Apr 20, 2013
The problem with the code is on line 14 and says undefined reference to `push(int)
Code:
#include<iostream>
using namespace std;
void push(int n);
int pop(int &n);
struct elem{
int key;
[Code]...
View 2 Replies
View Related
Aug 20, 2014
Can I a have one pointer with two reference in it. Here's what I've got.
Code:
char* c;
char x='x' , y='y';
c = &x;
c = &y; -- or --
Code: char* c[2];
char x='x' , y='y';
c[0] = &x;
c[1] = &y;
If it's possible I want to apply it to make AST.
View 8 Replies
View Related
Oct 25, 2013
Write a function called breakThree that will accept a 3 digit integer and returns each of the numbers individually. This function will take four paramaters. The first parameter is the three digit number to break apart. Parameters 2 through 4 are passed by reference and will be used to return each of the numbers back to main.
You should make sure that the input into the function is a 3-digit number. If it is not a three digit number the breakThree function should simply return false. If it is a three digit number the breakThree function should break the number apart, and store each of the numbers in the parameters passed by reference.
In main you should get the number from input and then output each of the numbers on a separate line.
What not to use
global variables
cin in breakThree function
cout in breakThree function
goto statements
#include <iostream>
using namespace std;
void separate(int a, int b, int c, int d);
int main(int argc, const char * argv[]) {
int num;
[Code] ....
View 4 Replies
View Related