declarations

C++: Asterisks and Pointers

I've recently decided that I just have to finally learn C/C++, and there is one thing I do not really understand about pointers or more precisely, their definition. How about these examples: int* test; int *test; int * test; int* test,test2; int *test,test2; int * test,test2; Now, to my understanding, the first 3 cases are all doin...

What is the difference between these declarations in C?

Hi friends, I am Manoj here to ask a question again. In C and C++ what do the following declarations do? const int * i; int * const i; const volatile int ip; const int *i; Are any of the above declarations wrong? If not what is the meaning and differences between them? What are the useful uses of above declarations (I mean in whic...

Why is volatile needed in c?

Why is volatile needed in C? What is it used for? What will it do? ...

Variable declaration placement in C

I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement rules for C89/ANSI C? The following code compiles successfully with "gcc -std=c89" and "gcc -ansi": #include <stdio.h> int main() { int i;...

C# member variable initialization; best practice?

Is it better to initialize class member variables on declaration private List<Thing> _things = new List<Thing>(); private int _arb = 99; or in the default constructor? private List<Thing> _things; private int _arb; public TheClass() { _things = new List<Thing>(); _arb = 99; } Is it simply a matter of style or are there perform...

C++ Nested classes forward declaration error

I am trying to declare and use a class B inside of a class A and define B outside A. I know for a fact that this is possible because Bjarne Stroustrup uses this in his book "The C++ programming language" (page 293,for example the String and Srep classes). So this is my minimal piece of code that causes problems class A{ struct B; // fo...

Why #include <stdio.h> is *not* required to use printf()?

Session transcript: >type lookma.c int main() { printf("%s", "no stdio.h"); } >cl lookma.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. lookma.c Microsoft (R) Incremental Linker Version 8.00.50727.762 Copyright (C) Microsoft Corporation. ...

What (not) to declare when implementing an interface with an abstract class?

I have an interface A, for which I have to supply a few different implementations. However, those implementations share some helper methods, so I moved those methods to an abstract base class. Interface A { void doX(); } abstract Class B implements A { protected void commonY() { // ... } @Override public abstract void doX(); } ...

Cant declare variables after statements in DevC++

Hey guys, The trouble here is that i cant declare variables inside a function after the function already has some statements in it. Declaring at the start works fine, but after something, it gives a parse error. for example: int main() { int b; b = sisesta(); float st[b]; return 0; } Id like to declare an array st with its size ...

Variable/Type declaration private by default

Hello, Is there a way to make the default access modifier public for variable/method/class declarations? I think by default, class declarations are private yes? ...

Automatically separate class definitions from declarations?

I am using a library that consists almost entirely of templated classes and functions in header files, like this: // foo.h template<class T> class Foo { Foo(){} void computeXYZ() { /* heavy code */ } }; template<class T> void processFoo(const Foo<T>& foo) { /* more heavy code */ } Now this is bad because compile times are unbearab...

Declaring and initializing a variable in a Conditional or Control statement in C++

In Stroustrup's The C++ Programming Language: Special Edition (3rd Ed), Stroustrup writes that the declaration and initialization of variables in the conditionals of control statements is not only allowed, but encouraged. He writes that he encourages it because it reduces the scope of the variables to only the scope that they are requir...

Complex Declarations

How to interpret complex declarations like : int * (* (*fp1) (int) ) [10]; --->declaration 1 int *( *( *[5])())(); -------->declaration 2 Is there any rule that should be followed to understand the above declarations? ...

The right method of sharing database variables (asp.net)

I have been sharing database variables using the following code: Namespace DataAccessVariables Public Class Vars Public Shared s As String Public Shared con As String = WebConfigurationManager.ConnectionStrings("Dev").ToString() Public Shared c As New SqlConnection(con) Public Shared x As New SqlComma...

change xmlns too when changing charset?

Should I alter the xmlns into 'el' from 'en' when setting up a webpage in ISO-8859-7 (Greek)? So it woulb be: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="el" lang="el"> ...

C# Nested Classes, Clean up Declaration

Hello, Is there a way in C# to tidy up the following class declaration? namespace Application.Namespace { public class MasterClass { public class FlyingSaucer { public class Rotator { public class Cube { Still maintaining the class structure, just cleaning...