answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

A full node is a node with two children Prove that the number of full nodes plus one is equal to the number of leaves in a binary tree?

Let N = the number of nodes, F = number of full nodes, L = the

number of leaves, and H = the number of nodes with one child (or half nodes).

The total number of nodes in a binary tree equals N = F + H + L.

Because each full node is incident on two outgoing edges, each half node is

incident on one outgoing edge, and each leaf is incident on no outgoing edge it

follows that the total number of edges in a binary tree equals 2F + H. It is also

true that the total number of edges in a tree equals N 1. Thus,

2F + H = N 1

H = N 1 2F

Subbing this value of H into N = F + H + L gives,

N = F + N 1 2F + L

N N + 1 = F + L

F + 1 = L

What array shows factors of18?

2 on top and bottom 4 in the middle on right and left

What is sprt client interface?

Check out supportsoft.com. See something familiar? I had to go into the registry and delete all the supportsoft entries. Don't mess with the registry unless you know what you're doing though. Misty

What does the grade C stand for?

it just represents a slightly below average grade, it does not stand for anything

rong, it means could do better... da

What is a virtual table in C?

A virtual table, or "vtable", is a mechanism used in Programming languages to support dynamic polymorphism, i.e., run-time method binding. Hope ive helped. Each function has an address in memory somewhere. Function names are just pretty ways of referring to a position in memory. When a program is linked (after the compiler is finished compiling) all those names are replaced with hardcoded memory addresses.

class Foobar

{

public:

int i;

void Something() {i = 0;}

};

int main()

{

Foobar f;

f.Something();

return 0;

}

You can tell even before execution that f.Something() is referring to the Something in Foobar. The linker will be able to replace that with an address pointing directly at Something.Draw().

This works pretty well until you bring in polymorphism because the linker is unable to tell which function to call. For example in C++:

class Foobar

{

public:

int i;

Foobar() {i = -1;}

virtual void FuncA() {i = 0;}

void FuncB() {i = 10;}

};

class Foo: public Foobar

{

public:

virtual void FuncA() {i = 1;}

void FuncB() {i = 11;}

};

class Bar: public Foobar

{

public:

virtual void FuncA() {i = 2;}

void FuncB() {i = 12;}

};

void FoobarFunc(Foobar* fb)

{

cout << fb->i << endl;

fb->FuncA();

cout << fb->i << endl;

fb->FuncB();

cout << fb->i << endl << endl;

}

void FooFunc(Foo* f)

{

cout << f->i << endl;

f->FuncA();

cout << f->i << endl;

f->FuncB();

cout << f->i << endl << endl;

}

int main()

{

Foobar fb;

Foo f;

Bar b;

Foo OtherFoo;

FoobarFunc(&fb);

FoobarFunc(&f);

FoobarFunc(&b);

FooFunc(&OtherFoo);

return 0;

}

In this excerpt, both Foo and Bar inherit from Foobar. FuncA is a virtual function while FuncB is not. The integer i is being set to see the results of our actions.

Notice how in FoobarFunc, you are unable to tell beforehand what address to replace FuncA and FuncB with! In order to solve this, virtual tables are created.

Normally, functions are not stored with the data of the class at all. So in our very first Foobar example with no inheritance, the class would only be 4 bytes long (excluding any compiler magic). However, when you declare something virtual, you're actually declaring a pointer to a function so each virtual function you have will increase the class size by the size of a pointer. The pointers will be populated by the constructors under the hood which is one reason why you cannot have virtual constructors. If you have many virtual functions, you end up with many pointers, which are organized into a table... the v-table. Each class will have its own unique v-table.

When a child class is constructed, the parent class's constructor is called before the child class's constructor is called. Each classes constructor will put the addresses of all the virtual functions it has into the v-table. In our example, when Foo is instantiated, Foobar's constructor is called first. Foobar's constructor will place the memory location of Foobar.FuncA into the v-table. Once Foobar's constructor is done, Foo's constructor will execute, placing Foo.FuncA into the table.

In FoobarFunc the line fb->FuncA(), actually replaced by an address to the v-table. When that line is executed, the computer will go to that location in the v-table, fetch the address of the function, and then jump to that location in memory. Because of how the constructors setup the v-table, you end up calling the correct function.

If you look at the example, you'll notice I have included FuncB which is not declared virtual to highlight the difference between virtual and nonvirtual functions. In FoobarFunc, the parameter is Foobar. Because FuncB is not virtual, there is no entry for FuncB in the v-table. The compiler/linker will hardcode the address in the binary and cause the program to always execute Foobar.FuncB no matter what gets passed in as the parameter. No polymorphism. In FooFunc, the parameter is Foo. Foo.FuncB will always execute in that function. Again, no polymorphism.

What is a word for performing at high level?

class-leading performance / top-tier performance / advanced performance

A C program to store students record in a file?

#include<stdio.h>

void main()

{

FILE *fp;

char name[20],ch;

char *roll;

fp=fopen("specifies file path","w");

if(fp!=NULL)

{

do{

printf("input roll_no");

gets(roll);

printf("\ninput student name");

gets(name);

fputs(roll,fp);

fputs("\t",fp);

fputs(name,fp);

fputs("\n",fp);

printf("you want to continue y/n");

ch=getch();

}while(ch=='y');

}

}

Traversing in Doubly Linked List is faster then Singly Linked List?

Traversing a doubly linked list is generally faster than traversing a singly linked list, but the speedup depends on how you do the traversal:

  • Traversing from first to last node: No difference.
  • Random access: Doubly linked list is faster, the difference is a fixed factor. (Like twice as fast. Which makes it still very slow for random access compared to arrays.)
  • Reverse order: Doubly linked list is just as fast traversing "backwards" as "forwards", while a singly linked list traversing in reverse order needs to traverse the entire list once for every element in the list - it is a LOT slower. (Time complexity O(n) for doubly linked list, O(n*n) for singly linked, if you are familiar with the notation.)
If you are talking about the computer science "big O notation", doubly linked and singly liked lists are the same. This is because the Big O notation ignores fixed factors and only looks at how time increases with the length of the list, and in this respect the two are the same. (Except for the special case of traversing the list in reverse order. Even here a singly linked list could do it in O(n) time - same as a doubly linked list - by reversing the list (O(n)) before traversing it (O(n)) for a total time of 2*O(n), which by the rules of Big O is the same as O(n).)

Write a program that converts a decimal number to crossponding string .Decimal Number is accepted as command line input at the time of execution?

#include
#include

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
string myNumber = "";
cout << endl << "Enter a number: ";
cin >> myNumber;

cout << endl << "You number was saved as string: "" << myNumber << """ << endl;

system("PAUSE");
return 0;
}

Two numbers are input through the keyboard into two locations C and D write a program in c to interchange the contents of C and D?

#include<iostream.h>

main()

{

int C,D,E;

cout<<"Number at location C=";

cin>>C;

cout<<"Number at location D=";

cin>>D;

E=C;

C=D;

D=E;

cout<<"New Number At Location C="<<C<<endl;

cout<<"New Number At Location D="<<D<<endl;

}

How do you allocate memory dynamically for a string of unknown size in c?

With function strdup (here is an implementation, if you don't have one already)

char *strdup (const char *f)

{

size_t len;

char *to;

len= strlen (f);

to = malloc (len+1);

if (to) memcpy (to, f, len+1);

return to;

}

What does booking include?

Well, if you are referring to booking for a flight or travel via airplane then you will need a valid ID, for international you need your passport then basic personal information for the online forms and then a credit card info for the payment. You can also pay over the counter using the booking confirmation code.

How do you perform multiplication of two numbers without using the multiplication operator?

By using repeated addition. Consider two numbers a and b. If you want to find a*b then you can add the numbers repeatedly in a loop to get the product. Eg:

product = a;

for( i=1; i<=b; i++)

product+= a;

What is the utility of storage class in c?

In C there are four storage classes: auto, static, extern and register. These storage classes essentially define the scope or visibility of a name (a function or variable). All four are inherited from B, the language from which C evolved.

  • The auto storage class is used to explicitly declare a non-static local variable. However, given that all non-static local variables are implicitly automatic in C, explicit use of the auto storage class is therefore redundant in C. Moreover, in C++11, explicit use of the auto storage class was dropped entirely; the auto keyword is now used for automatic type deduction in C++.
  • The static storage class is used to explicitly declare a static local variable. In addition, all global variables and functions are implicitly static and have external linkage, but if explicitly declared static they have internal linkage only.
  • The extern storage class is used to allow access to a name that has external linkage.
  • The register storage class is used to define a variable that should be allocated in a CPU register rather than in working memory (RAM).

Comparison of all algorithms in data structures?

Arrays are datastructures which use continguous memory , and data allocation happens at compilation, so it is faster in execution . similarly in stacks and queue. The memory usage is lesser compared to other data type as it does not require pointers. It is fixed memory allocation so cannot be used until u are sure about the size of the data. Moreover if u do a wrong estimation about the size of data required then can lead to memory shortage or if declared more then it leads to Memory wastage.Searching can be easy in arrays,stacks and queues,however insertion and deletion is quite difficult in these data structures. Searching can also be easy in binary trees as data is sorted and stored . Accessing data is faster here as it allows random access to data.In arrays u can use only one type of data.

Linked list, graphs, trees are non continguous memory ,i.e they use heap memory. Here data is allocated in run time so execution may take more time compared to above, As data is allocated in run time u will also need memory allocator to keep track of available memory and allocate them. Memory usage is also more as we each node has to have the additional info about the address of the next data.so its time consuming compared to above. As the size of data is not fixed can be used in programs where we are not aware of size of data before execution. Here data is sequencially accessed which means accessing data is slow .to access 30th element u will have to traverse through 30 elements. However data insertion and deletion is faster all that we need to do is change address of the pointer. There is no memory wastage here as memory is not stored for this but its more flexible. Here u can store different data types unlike arrays. -

Shruthi.B.O

Is run time initialization of an array an initialization or an assignment?

It is an initialisation. You cannot assign values to a dynamic array until it has been initialised. Static arrays can be initialised at compile time. They can also be assigned at compile time.

void main()

{

// Compile time:

// =========

// Initialise a static array.

int arr1[10];

// Initialise and assign a static array.

int arr2[10] = {0,1,2,3,4,5,6,7,8,9};

// Runtime:

// ======

// Dynamic array (size unknown, no memory allocated)

int* pArr[];

// Initialise (size known, allocate memory, 40 bytes):

pArr = ( int* ) malloc( 10 * sizeof( int ));

// Assign (set values of elements):

int x;

for(x=0;x<10;++x)

pArr[x] = x;

// Uninitialise (release memory).

free( pArr );

return( 0 );

}