Basic Concept of c++

Basic Concepts of c++

Data type Checking in c++

#include <typeinfo>
char x;cout<<typeid(x).name();

output =c


String to integer conversion

  #include <string> 
 using namespace std;  
 string s = "100"; 
 int i = stoi(str1); 
 string s2 = "6.85"; 
 int i2 = stoi(s2); 
 string s3= "100 my"; 
 int i3 = stoi(s3);
 cout<<i<<" "<<i2<<" "<<i3;

output=100 6 100

Same atoi() function also covert character array to integer-

const char *s = "100 my";
int n = atoi(s); 
cout<<s;

output=100

Integer to string

int i=100;
string s= to_string(i);

String length-
string s = "abc";
cout << "The length of the s string is: " << s.length();


output-
The length of the s string is: 3

Access a string-

string s = "abc";
cout << s[0];
// Outputs a


Array Declaration-

int a[n];     //N is enter by user
int a[10][10];
Node *node[6];
int a[5]={1,2,4};     //is same as a[5]={1,2,4}

int a[6];
a[6]={6,7,3,4,3,3};       // It gives error

int a[6]={6,7,3,4,3,3};     // This not gives error

Array Declaration in Function

Node * function(int m[][N]){}      //This is valid
Node * function(int m[N][N]){}    //This is valid
Node * function(int m[N][]){}    //This is not valid





Size of Array-

int s=sizeof(a)/sizeof(a[0]);

Creating Structure in c++-

struct Node 

    int data; 
    Node *left, *right; 

}; 


// For creating a new node
Node* newNode(int data) 

    Node* node = new Node; 
    node->data = data; 
    node->left = node->right = NULL; 
    return (node); 






























Comments