top of page

My notes-Day 1

  • Writer: sondip poul singh
    sondip poul singh
  • Feb 1, 2019
  • 1 min read

float vs double:

As the name implies, a double has 2x the precision of float. In general a double has 15 decimal digits of precision, while float has 7.

https://stackoverflow.com/questions/2386772/what-is-the-difference-between-float-and-double

%lf vs %f:

no effect on printf

have effects on scanf

https://stackoverflow.com/questions/4264127/correct-format-specifier-for-double-in-printf

local variable vs static:

for (int i = 0; i < 5; ++i)

{

int n = 0;

printf("%d ", ++n); // prints 1 1 1 1 1 - the previous value is lost

}

for (int i = 0; i < 5; ++i)

{

static int n = 0;

printf("%d ", ++n); // prints 1 2 3 4 5 - the value persists

}

Structure in c++:

Structure is a collection of variables of different data types under a single name. It is similar to a class in that, both holds a collecion of data of different data types.

#include<iostream>

#include <string>

using namespace std;

Struct person{

string name;

int age;

}

int main()

{

person p;

cin>>p.name>>p.age;

cout<<p.name<<p.age;

}

Structure Vs Class:

The only difference between a class and a struct in C++ is that structs have default public members and bases and classes have default private members .

Comments


bottom of page