C/C++ Beginner's Guide and Post Basic Questions here

ico

Super Moderator
Staff member
Buy this - C++ Primer book : Josee Lajoie, 8131775275, 9788131775271 - BookAdda.com India

Out of stock on Flipkart.
 

MelisaStewart

Right off the assembly line
I think above is a thread that actually suits the content of the same. Programming is nothing but a set of commands created by a developer which is then coded into the machine so that the machine performs a set of tasks depending on user inputs or independently. such a fine post it is.
 

nims11

BIOS Terminator
I think above is a thread that actually suits the content of the same. Programming is nothing but a set of commands created by a developer which is then coded into the machine so that the machine performs a set of tasks depending on user inputs or independently. such a fine post it is.

This statement is as abstract as "Mathematics is all about addition and subtraction"
 

vickybat

I am the night...I am...
thanks, is the book good for beginners? and what about the site? ill ask in some local shops...

Get this:

OBJECT ORIENTED PROGRAMMING IN C++ 4ED 4 Edition - Buy OBJECT ORIENTED PROGRAMMING IN C++ 4ED 4 Edition by Robert Lafore Online at Best Prices in India - Flipkart.com
 

a.ravi

New to this forum
Can any one tell me, how i can perform file operations copy, move in C??
May i know the compiler ua using?if ua using linux interface u can have the copy of the program by following steps:
1.from the editor press escape
2.then press shift+:(colon)
3.type wq then leave a space and give the new name to which u want to copy.
4.Press enter
now u can open the new file which has been copied.
ex: wq newname.cpp
 

aaruni

The Linux Guy
What's the maximum number of if-else statements allowed in C++?

if-else ladder you mean? the deepest level in an if-else ladder?

because, I think there may be a limit in the if-else ladder, but otherwise, there may be infinite number of uses of if-else...
 

Vignesh B

Youngling
if-else ladder you mean? the deepest level in an if-else ladder?

because, I think there may be a limit in the if-else ladder, but otherwise, there may be infinite number of uses of if-else...
I didn't mean the if-else ladder. I just asked about the maximum number of uses of if-else in a program. I remember reading somewhere about the limit.
Since you pointed it out am also curious to know the deepest level in an if-else ladder.
 

nims11

BIOS Terminator
there is no such limit on number of if-else or depth of if-else imposed by the C language specification.
 

gigyaster

Journeyman
okay, a new question in here.

I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
    int num; char i=0,j; char a[11]={0,0,0,0,0,0,0,0,0,0,'\0'};
    char string[11];
    printf("\nEnter the decimal number\n"); scanf("%d",&num);
    while(num>0)
    {
        a[i]=num%2;
        i++;
        num=num/2;
    }
    printf("\nThe Binary equivalent is\n");
    for(j=9;j>=0;j--)
    {
        printf("%d",a[j]);
    }
    


}

Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use printf("%s",string) and get the binary output ?
 

Neuron

Electronic.
okay, a new question in here.

I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
    int num; char i=0,j; char a[11]={0,0,0,0,0,0,0,0,0,0,'\0'};
    char string[11];
    printf("\nEnter the decimal number\n"); scanf("%d",&num);
    while(num>0)
    {
        a[i]=num%2;
        i++;
        num=num/2;
    }
    printf("\nThe Binary equivalent is\n");
    for(j=9;j>=0;j--)
    {
        printf("%d",a[j]);
    }
    


}

Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use printf("%s",string) and get the binary output ?

The quickest way to do this is to add 48 to the contents of the int array to get the ascii equivalent char value of that digit. For example, '1' 's ascii value is 49. Add 48 to 1 and store it in the char array. Or you can use switch-case statements to individually put the ascii value of digits into arrays.
 

RBX

In the zone
[C++]

In a method, I have a pointer to a node, how do I set node to NULL using that pointer?
Also, can only use delete(), and not free().

Edit: Precisely, I need to delete root of tree, but when it's the last element, it doesn't work because tree's class always has a pointer to it.

Edit: In this root is accessible directly since it's in a friend class and I'm using iterative approach, so I just checked if it was root and a leaf and then set it to NULL.
 
Last edited:

rohitshubham

Ambassador of Buzz
[C++]

In a method, I have a pointer to a node, how do I set node to NULL using that pointer?
Also, can only use delete(), and not free().

Edit: Precisely, I need to delete root of tree, but when it's the last element, it doesn't work because tree's class always has a pointer to it.

Edit: In this root is accessible directly since it's in a friend class and I'm using iterative approach, so I just checked if it was root and a leaf and then set it to NULL.
i am sorry , i am not getting your question..are you making threaded tree? coz you're saying you root node always has a pointer to it;
BTW if you want to set the value NULL if method has been called by pointer to pointer(void abc(node **,int))then you could set the value of node such as tree_1 as NULL by using (*tree_1)->left=NULL ; which i guess is not the question you are asking.
 
Last edited:
Top Bottom