cs Sep 4, 2014
identifier which does not have memory : void f()
int main()
{
f() ; f is called, () is the functional operator
}
main is a definition while f is a declaration..
define f now :: list out what it does..
declaration " associate a type with an identifier"
definition " this also allocates memory", (creates an object)
string s; //definition
declaration which is not a definition for a variable ?
class Myclass; //declaration only.
class Mathclass{ }; //declaration only
variable declaration which is not a definition..
initialization -- gives the object a value.
[] square brackets;
<> angle brackets
{} curly braces
type -unsafe allows implicit conversions
type-safe -- does not allow implicit conversions
g++ option for c++11
flag -std=c++11
REN project
create a new type : class Mathclass { };
data definition not a declaration
void f(int x); (not definition, only declaration of x here)
{
}
how to add code to the above so we allocate memory to it.
f(2); allocates memory.
struct s {int x ; }; creating a new type , declaring x to be an integer within it., still not an object and no memory allocated.
can't do struct s{int x=2;}; as this does not have a memory.
Example of string literal : "hello" object with no name
eg. of numeric literal : 2
character literal : 'a'
Not every unnamed object is a literal but all literals
unnamed object which is not an identifier.
new int; basically unnamed object but not an identifier. allocates memory.
new int(2); allocating memory and initialize this.. initializing an unnamed object.
cout << new int(2) ;; would display the memory address where the object was allocated.
cout << * new int(2) ; dereferencing operator..
int *p = new int(2);
cout<<*p;
compiletc from the list of apps install.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home