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

You want a algorithm to convert tree to binary tree?

The simplest way to do this is to iterate over your general tree and add each value you find to a new binary tree. The logic of the binary tree will take care of the "conversion" for you.

Note: The problem with this is that your "general" tree might already contain data in sorted order. If this is the case and you're doing an in-order traversal, then you just might be building yourself a worst-case tree.

Binary search in array in c?

// answer in C-style pseudo-code

// all division should be rounded up

// search will return the index of the number found, or -1 if it was not found

// nums is the array of numbers we're searching through

// num is the specific number we want to find in nums

// current is the index we are currently inspecting

// start is the first index of nums (typically 0)

// end is the last index of nums (typically the length - 1)

// preconditions: nums must be sorted or function is nondeterministic

int search( int[] nums, int num, int current, int start, int end ) {

if( nums[current] end ) { // target not in list

return -1;

}else if( nums[current] > num ) { // search to the left

return search( nums, num, current - ((current - start)/2), start, current );

}else if( nums[current] < num ) { // search to the right

return search( nums, num, current + ((end - current)/2), current, end );

}

}

// convenience function to start the search

int search( int[] nums, int num ) {

return search(nums, num, (nums.length/2), 0, nums.length - 1);

}

What is Abstraction in C?

C is not an object-oriented programming language and therefore has no concept of abstract classes.

In C++, however, an abstract class is a base class that declares one or more pure-virtual functions. An abstract base class is also known as an abstract data type (ADT). Pure-virtual functions differ from virtual functions in that virtual functions are expected to be overridden (but needn't be) while a pure-virtual function must be overridden (but needn't be implemented by the ADT). Once overridden by a derived class, the function reverts to being a virtual function with respect to further derivatives. However, only classes that provide or inherit a complete implementation of the pure-virtual interface can be instantiated in their own right; those that do not are themselves abstract data types.

Write a program in C language to convert infix expression to postfix expression?

#

/**************************//**********cReDo**********//*****mchinmay@live.com***///C PROGRAM TO CONVERT GIVEN VALID INFIX EXPRESSION INTO POSTFIX EXPRESSION USING STACKS.#include#include#include#define MAX 20char stack[MAX];int top=-1;char pop();void push(char item);int prcd(char symbol){switch(symbol){case '+':case '-':return 2;break;case '*':case '/':return 4;break;case '^':case '$':return 6;break;case '(':case ')':case '#':return 1;break;}}int isoperator(char symbol){switch(symbol){case '+':case '-':case '*':case '/':case '^':case '$':case '(':case ')':return 1;break;default:return 0;}}void convertip(char infix[],char postfix[]){int i,symbol,j=0;stack[++top]='#';for(i=0;i{symbol=infix[i];if(isoperator(symbol)==0){postfix[j]=symbol;j++;}else{if(symbol=='(')push(symbol);else if(symbol==')'){while(stack[top]!='('){postfix[j]=pop();j++;}pop();//pop out (.}else{if(prcd(symbol)>prcd(stack[top]))push(symbol);else{while(prcd(symbol)<=prcd(stack[top])){postfix[j]=pop();j++;}push(symbol);}//end of else.}//end of else.}//end of else.}//end of for.while(stack[top]!='#'){postfix[j]=pop();j++;}postfix[j]='\0';//null terminate string.}void main(){char infix[20],postfix[20];clrscr();printf("Enter the valid infix string:\n");gets(infix);convertip(infix,postfix);printf("The corresponding postfix string is:\n");puts(postfix);getch();}void push(char item){top++;stack[top]=item;}char pop(){char a;a=stack[top];top--;return a;}//mail me: mchinmay@live.com

What is putchar function in c?

putchar used to write one character to output device Example putchar (variable_name); #include<stdio.h> void main() { char alpha='x'; clrscr(); putchar(alpha); putchar('\n'); /*or*/ putchar('\Y'); getch(); }

What the difference between pretest loop and posttest loops?

The difference is that pre means before and post means after in Latin so it's tested before or after. :)

How do you write a program in C language to get the ASCII values of all the letters of the alphabet?

#include<iostream.h>

void main()

{

int x;

char y;

cin>>y;

x=y;

cout<<"ASCII VALUE"<<x;

}

Or rather:

for (c='A'; c<='Z'; ++c) printf ("'%c' %d 0x%x\n", c, c, c);

for (c='a'; c<='z'; ++c) printf ("'%c' %d 0x%x\n", c, c, c);

Explain the various data types available in SQL?

You retrieve, store, and update SQL3 datatypes the same way you do other datatypes. You use either ResultSet. getXXX or CallableStatement. getXXX methods to retrieve them, PreparedStatement. setXXX methods to store them, and updateXXX to update them. Probably 90 percent of the operations performed on SQL3 types involve using the getXXX , setXXX , and updateXXX methods. The following table shows which methods to use:

SQL3 type

getXXX method

setXXX method

updateXXX methodBLOB

getBlob

setBlob

updateBlobCLOB

getClob

setClob

updateClobARRAY

getArray

setArray

updateArrayStructured type

getObject

setObject

updateObjectREF (structured type)

getRef

setRef

updateRef

For example, the following code fragment retrieves an SQL ARRAY value. For this example, the column SCORES in the table STUDENTS contains values of type ARRAY . The variable stmt is a Statement object. ResultSet rs = stmt.executeQuery( "SELECT SCORES FROM STUDENTS WHERE ID = 2238"); rs.next(); Array scores = rs.getArray("SCORES");

The variable scores is a logical pointer to the SQL ARRAY object stored in the table STUDENTS in the row for student 2238.

If you want to store a value in the database, you use the appropriate setXXX method. For example, the following code fragment, in which rs is a ResultSet object, stores a Clob object: Clob notes = rs.getClob("NOTES"); PreparedStatement pstmt = con.prepareStatement( "UPDATE MARKETS SET COMMENTS = ? WHERE SALES < 1000000", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); pstmt.setClob(1, notes);

This code sets notes as the first parameter in the update statement being sent to the database. The CLOB value designated by notes will be stored in the table MARKETS in column COMMENTS in every row where the value in the column SALES is less than one million

Which one is the best and efficient sort?

There are a great many sorts, Mergesort and Quicksort being among the most popular. These both have on the order of n*log n expected case runtime, and while Quicksort can get as bad as n^2, this is unlikely due to most implementations using a random pivot.

If you can make the assumption that ONLY NUMBERS will be sorted, you can use RadixSort, which is the fastest known sort for numbers.

As for how to sort in particular programming languages, consult your local API (in C++ it is in the STL's "algorithm" include file).

Write a program in c to sort an unsorted array using selection sort?

#include<stdio.h> #include<conio.h> int main() { char str[100],temp; int i,j; clrscr(); printf("Enter the string :"); gets(str); printf("%s in ascending order is -> ",str); for(i=0;str[i];i++) { for(j=i+1;str[j];j++) { if(str[j]<str[i]) { temp=str[j]; str[j]=str[i]; str[i]=temp; } } } printf("%s\n",str); getch(); return 0; } Output: Enter the string : syntax syntax in ascending order is -> anstxy

What is required in order to perform a binary search?

1. direct access to the elements

2. the elements are sorted

Why Java is called object oriented programming language?

Java is an object-oriented computer programming language that is used for application as well as system software development. It is best for web based applications such as servlets, XML design...etc., i.e. the applications that can run on the Internet. It can be used as front end tool for the back end database application. for example, the famous Oracle Database management system was designed using Java technology. It is also platform independent. meaning it can run under most platforms and OSs. Java technology was created as a computer programming tool in a small, secret effort called "the Green Project" at Sun Microsystems in 1991.

The secret "Green Team," fully staffed at 13 people and led by James Gosling, locked themselves away in an anonymous office on Sand Hill Road in Menlo Park, cut off all regular communications with Sun, and worked around the clock for 18 months.

They were trying to anticipate and plan for the "next wave" in computing. Their initial conclusion was that at least one significant trend would be the convergence of digitally controlled consumer devices and computers.

A device-independent programming language code-named "Oak" was the result.

To demonstrate how this new language could power the future of digital devices, the Green Team developed an interactive, handheld home-entertainment device controller targeted at the digital cable television industry. But the idea was too far ahead of its time, and the digital cable television industry wasn't ready for the leap forward that Java technology offered them.

As it turns out, the Internet was ready for Java technology, and just in time for its initial public introduction in 1995, the team was able to announce that the Netscape Navigator Internet browser would incorporate Java technology.

Now, nearing its twelfth year, the Java platform has attracted over 5 million software developers, worldwide use in every major industry segment, and a presence in a wide range of devices, computers, and networks of any programming technology.

In fact, its versatility, efficiency, platform portability, and security have made it the ideal technology for network computing, so that today, Java powers more than 4.5 billion devices: * over 800 million PCs * over 1.5 billion mobile phones and other handheld devices (source: Ovum) * 2.2 billion smart cards * plus set-top boxes, printers, web cams, games, car navigation systems, lottery terminals, medical devices, parking payment stations, etc. Today, you can find Java technology in networks and devices that range from the Internet and scientific supercomputers to laptops and cell phones, from Wall Street market simulators to home game players and credit cards -- just about everywhere.

The best way to preview these applications is to explore java.com, the ultimate marketplace, showcase, and central information resource for businesses, consumers, and software developers who use Java technology.

Why Software Developers Choose Java Technology

The Java programming language has been thoroughly refined, extended, tested, and proven by an active community of over five million software developers.

Mature, extremely robust, and surprisingly versatile Java technology has become invaluable in allowing developers to: * Write software on one platform and run it on practically any other platform * Create programs to run within a web browser and web services * Develop server-side applications for online forums, stores, polls, HTML forms processing, and more * Combine Java technology-based applications or services to create highly customized applications or services * Write powerful and efficient applications for mobile phones, remote processors, low-cost consumer products, and practically any device with a digital heartbeat

What is spanning tree in data structure?

A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.

When was Principles of Compiler Design created?

Principles of Compiler Design was created in 1977.

Write a program in C language to implement the insertion and deletion operations in a circular queue?

//posted by Mr. VINOD KUMAR HOODA from HISAR, HARYANA

#include<stdio.h>

#include<conio.h>

void insert(int);

int delet(int);

void display(void);

void run(void);

void checkf(int z);

void checke(void);

int size=5;

int rear=-1;

int front=-1;

int queue[5]={55,66,77};

void main()

{

front+=1;

rear+=3;

int n;

int op;

printf("current queue is:");

display();

printf("\nPress:");

printf("\n1: for insertion of an element into the queue");

printf("\n2: for deletion of an element from the queue");

printf("\n3: check for full queue");

printf("\n4: check for empty queue");

printf("\n5: for exit\n");

scanf("%d",&op);

switch(op)

{

case 1:insert(size);break;

case 2:delet(size);break;

case 3:checkf(size); break;

case 4:checke(); break;

case 5:exit(1); break;

default:printf("\nWrong operator");

}

getch();

}

void insert(int n)

{

int item;

if(front!=-1&&rear!=n)

{

printf("\nEnter the item to be inserted");

scanf("%d",&item);

queue[rear+1]=item;

}

else

{

printf("\ncan not be inserted\n");

}

display();

}

int delet(int n)

{

printf("\ndeleted from queue\n");

if(front!=-1 && front!=rear)

{ run();

display();

}

else if(front!=-1 && front==rear)

{ run();

front=front-1;

display();

}

else if(front==-1)

{ printf("\nQueue is empty"); }

}

void display(void)

{

int i;

printf("\nDisplaying Queue\n");

for(i=0;i<size;i++)

printf("%d ",queue[i]);

}

void run(void)

{ int m,temp;

for(m=front;m<=rear-1;m++)

{temp=queue[m];

queue[m]=queue[m+1];

}

for(m=rear;m<size;m++)

{ queue[m]=0; }

rear=rear-1;

}

void checkf(int z)

{ if(rear==z-1)

{ printf("Queue is Full \n");

}

else

{ printf("Queue is not Full, new values can be inserted. \n");

}

}

void checke(void)

{ if(front==-1)

{ printf("Queue is empty \n");

}

else

{ printf("Queue is not empty, new values can be deleted. \n");

}

}

What are Mistakes that cause a running program to produce incorrect results?

You could call it a bug in general but more specifically code with no syntax errors (i.e. it compiles and runs) but doesn't produce the output you expect would be called a semantic error.

Difference between high level and low level languages?

Low level languages bring you close to the machine, e.g. Assembly, or C. High level languages obfuscate more, so it makes life as a programmer easier. Consider:

Python, garbage collected.

C, not garbage collected.

Java, garbage collected.

And so forth.

C does has its uses, still: how could one make a hardware driver with a garbage collected language?

What is the operator that cannot be overloaded?

There are 5 operators which cannot be overloaded. They are:

* .* - class member access operator

* :: - scope resolution operator

* . - dot operator

* ?:: - conditional operator

* Sizeof() - operator Note:- This is possible only in C++.

What is a universal pointer?

A universal pointer is a pointer variable that does not specify the type being pointed at. That is, it can be used to store any memory address regardless of the type of object actually stored at that address. It can be likened to a variable type, but you cannot dereference the memory address without providing some mechanism for determining the actual type stored at that memory address. Generally you would use a universal pointer when you don't actually care what type resides at the address, you are only interested in the address itself. But just as a typed pointer can point to 0 (or NULL), so can a universal pointer, which simply means it points at nothing at all.

How do you find the fectorial in C programming?

#include<stdio.h>

#include<conio.h>

void main()

{

int fact,f;

printf("Enter number");

scanf("%d",&f);

fact=1;

while(f>1)

{

fact=fact*f;

f--;

}

printf("Factorial is: %d",fact);

}

Advantages and disadvantages of algorithm?

The advantages of algorithms are:

1.They are easy to understand

2.They are easy to implement

3.They are easy to modify

4.They are not dependent on any particular computer language.

What are the advantages and disadvantages of using cellphones?

The advantages of using cellphones are so many including mobility and convenience. However, there are many disadvantages as well which includes health hazards as a result of cellphones being electromagnetic devices.

Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.

Virus written in C?

And by the way, I know that "most virus' are written in Asm, and not any high level languages cuz they're too... uh... high, yeah. stupid f*ckin computer geeks, go jump off 21h and land in the stack. anyway, yes, my question (I am Agrybard) is really if there are any virus' written in C++, rather than just C, but either way I would appreciate any help. and yes, I've GOOGLED IT ALREADY! lol AGB