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

Why flowcharts are not good for object oriented programming?

Object oriented programming requires objects generally represented as classes to "talk" to other objects via methods/functions. This is a different approach from procedural languages where a procedure i.e. steps were constructed and written in the form of a flow chart.

For object-oriented programming the "flow" between objects is more important than the construction of a program. For this we use class diagrams. (using tools like rational rose). The methods themselves where the functioning takes place are so small and simple that for constructing them a flow chart is generally not required for a seasoned programmer. Thus, flowcharts are simply not a good instrument for oo programming because here data is given much more importance than the procedures that operate on them.

What program is the program that contains the language instructions or code to be converted?

There is no such thing: compiler translates but doesn't execute; interpreter executes, but doesn't translate.

Algorithm to reverse content of queue using stack?

  • #include

    #include

    #define SIZE 5

    struct tag

    {

    int a[SIZE];

    int top;

    }; //Structure definition for stack

    typedef struct tag stack;

    struct tagg

    {

    int items[SIZE];

    int rear;

    int front;

    }; //Structure definition for queue

    typedef struct tagg QUEUE;

    void push();

    int pop();

    void display();

    void rev(); //Function declarations(parameters not required at declaration)

    int main()

    {

    int ch, element, dnum;

    stack st;

    st.top= -1;

    do

    { //Displaying menu for operations on stack

    printf("\n1.) PUSH");

    printf("\n2.) POP");

    printf("\n3.) DISPLAY");

    printf("\n4.) REVERSE");

    printf("\n5.) EXIT");

    printf("\nEnter your choice: ");

    scanf("%d", &ch);

    switch(ch)

    {

    case 1: printf("\nEnter element to push: ");

    scanf("%d", &element);

    push(&st, element);

    break;

    case 2: dnum = pop(&st);

    if(dnum != -1)

    printf("\nDeleted element: %d", dnum);

    break;

    case 3: display(st);

    break;

    case 4: rev(&st);

    break;

    case 5: break;

    default: printf("\nWrong choice!! Enter choice again.");

    }

    }while(ch!=5);

    }

    void push(stack *s, int ele)

    {

    if(s->top -1)

    {

    printf("\nStack is empty");

    }

    else

    {

    for(i=s.top; i>=0; i--)

    {

    printf("\n%d", s.a[i]);

    }

    printf("\n");

    }

    }

    //Function to reverse a stack using queue

    void rev(stack *s)

    {

    QUEUE q;

    q.rear = -1;

    q.front = 0;

    if(s->top==-1)

    {

    printf("\nStack empty");

    return;

    }

    while((s->top) > -1)

    {

    q.items[++(q.rear)] = s->a[(s->top)--];

    }

    while(q.front <= q.rear)

    {

    s->a[++(s->top)] = q.items[(q.front)++];

    }

    } Use the two queues to simulate a stack.

  • Push all of the elements of the original queue to this stack.
  • Now pop each element from the stack and add it to the original queue.

Reversing a Stack using Queue.

How can write a c plus plus program to sort an integer array and name array using function overloading use dynamic memory allocation for both the array?

#include<iostream>

#include<vector>

#include<string>

#include<algorithm>

// forward declarations

void sort(std::vector<int>&);

void sort(std::vector<std::string>&);

int main()

{

std::vector<int> int_array = { 7, 3, 8, 6, 2, 9, 1, 4, 0, 5};

std::vector<std::string> str_array = { "John", "Bill", "Alan", "Craig"};

sort (int_array);

sort (str_array);

}

void sort(std::vector<int>& arr)

{

std::sort (arr.begin(), arr.end());

}

void sort(std::vector<std::string>& arr)

{

std::sort (arr.begin(), arr.end());

}

What does the auto specifier do?

It indicates that a variable's memory will automatically be preserved

How do you find the general equation of cone using C language?

If you mean the "general equation of a cone" to be the elliptical cone equation:

z = √( (x/a)2 + (y/b)2 )

... then the function in C to compute this given the proper variables is:

double genEqCone(const double x, const double y, const double a, const double b) {

const double X_A = (x/a);

const double Y_B = (y/b);

return sqrt((X_A * X_A) + (Y_B * Y_B));

}

How to write C multiplication table?

/******************************************

* C Program to print MultiplicationTable *

* Author of the Program: M.JAYAKUMAR..*

* Date 23 Nov 2006 *

* ***************************************/

#include<stdio.h>

main()

{

int i, p=1, table[10]; /* define integres and array */

/* ***************************

* Output Formating Begins

* ***************************/

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

printf("#");

printf("\n# Program to print Multiplication table of any number");

printf("\n# NOTE: To exit type 0 \n");

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

printf("#");

/* ***************************

* Output Formating ENDS

* ***************************/

while(p != 0)

{

printf("\nWhich table ");

scanf("%d",&p); /* takes input from input */

for(i=0;i<10;i++) /* Fills the array */

{

if(p==0) /* Stratagy to exit the program Benins */

{

printf("Exiting\n");

break;

} /* Stratagy to exit the program ends */

table[i]=i+1; /* Fills the array with numbers 1 - 10 */

printf("%2d x %2d = %2d\n", p, table[i], p * table[i]);

}

}

}

Compilers required in opensuselinux for c plus plus programming?

Most, if not all, Linux distributions have the compiler you would need to compile c and c++ programs, gcc, or the gnu c compiler chain. If you type "gcc --help" into the terminal, it will give you a short list of command line arguments that are needed, as well as briefly explain the various command line arguments. Man (manual) pages can be read by typing "man gcc" at a terminal prompt. Man pages are very thorough (read: very long) explanations of every possible use for a program or command.

If you do not have gcc installed (I don't know how you wouldn't), you should be able to use YAST to install it. Search for "gcc" and install the most recent package. You may need to install the header files, and possibly the kernel sources as well for some programming.

What is Remote Data Object?

A remote data object is one that would be located on a different "node". For instance, a node the hardware where the operating system resides, which houses a database. Nodes have IP addresses and names. Say that the main database resided on node "Payroll" (10.128.132.10). Via a database link, an object from another node "Accounting" (10.128.142.11) is referenced. An example of this could be a view which pulls data from a table in the Payroll database and joins it to a table in the Accounting database and the view shows data from both nodes.

Sorting numbers using user-defined functions in C programming?

Assume your numbers are into an array. Then write any user-defined function implementing any kind of sorting. I am giving example of bubble sort.

  1. void bubble(int a[],int n){
  2. int i,j,t;
  3. for(i=n-2;i>=0;i--){
  4. for(j=0;j<=i;j++){
  5. if(a[j]>a[j+1]){
  6. t=a[j];
  7. a[j]=a[j+1];
  8. a[j+1]=t;
  9. }
  10. }
  11. }
  12. }

Why are double quotes used in C programming?

In C programming, double quotes are used to indicate String literal.

char *s = "Hello World";

Where as single quotes are used to indicate a single character.

char x = 'a';

What data type is the is Yes or No?

In Java, that would be called "boolean". In other languages it may have different names, for example, "logical". In C, there is no true boolean data type, so people just use integer and if you want the integer to be true, you set it to 1 and if you want it to be false, you set it to 0.

Example of Fibonacci number in turbo complier and how to do?

#include #include void main() { int n,i,x,y,s=0; coutn; x=0; y=1; cout

How do you change data types range in c?

You can not change the range of a data type. It is a function of the implementation and is dependent on the word size of the implementation's computer hardware.

What operating systems are written in the C language?

They're not.

Perhaps since the advent of UNIX, it has become obvious that writing software in higher level languages makes for less debugging and more reliable code, but originally OSs were written in the assembler of the machine they ran on.

Believe it or not, most OS geeks think of "C" as a high level language. The fact that you can directly address all of memory and that it has a concept of interupt handling makes it an ideal candidate for portable OS code (consider that UNIX and later Linux now runs on virtually all hardware platforms).

Java specifically prevents you from directly accessing random memory. You can only address memory that Java has allocated to you in the form of objects. You can imagine writing a function that allowed java to directly access that memory ... but what would that function be written in? Probably C.

In fact, even version of the java engine I have seen was written in C or C++.

Way back when, the majority of programmers out there had experience with assemblers and C was such an advance that there was no reason to turn back.

By the way, the vast majority of OSs written in C still have a tiny bit of assembler associated with them associated with page handling and interupts.

In short C is the highest low level language, where you define "low level language" as one that can directly access memory by address instead of as an object. Alternately, you can say that C is high level language that has the advantage of being able to directly access memory by ... etc.

Problem is - the ability to talk about addresses instead of object handles makes it very easy to write bad code. And there is a LOT of bad C out there.

What is the use of default keyword?

default is used with (switch statement) to handle what'll happen if non of the defined cases happened.

ex:

int x=4;

switch(x)

{

case 1: cout<<"1"; break;

case 2: cout<<"2"; break;

case 3: cout<<"3"; break;

default : cout<<"It's not 1 or 2 or 3 ..! ";

}

in that case .. we'll see (It's not 1 or 2 or 3 ..!)

How do you convert capital to lower string in c using asc code?

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char str[99];

int i,len=0;

clrscr();

printf("Enter the string \n");

while ( i!=\n)

scanf("%s",str[i]);

len=strlen(str[i]);

//Printing the accepted value.

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

{

printf("%s",str[i]);

}

//Converting the case.

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

{

if(str[i]>='A' && str[i]<='Z')

{

str[i]+=35;

}

else

{

str[i]-=35;

}

}

//Printing the string converted string.

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

{

printf("%s",str[i]);

}

getch();

}

What is primary data type in C?

The terms "primary data type" and "secondary data type" are not exactly correct when working in C. Instead, C has what are called "primitive data types" or, in some references, "basic types" - types which can be affected by arithmetic operators.

Other data types include structs, arrays, and unions. Structs, arrays and unions cannot be affected as a whole by arithmetic operators, although the members within that are primitive data types can be.

Pointers can technically be affected by arithmetic operators, particularly +, -, ++ and --, but because their values are expected to be used as addresses, they're not considered to be primitive in nature.

There are three primitive data types in C: integers, real numbers and complex numbers. Integers have no decimal points and can be signed or unsigned, and real and complex numbers are signed and have decimal points. Boolean types are represented by integers, most commonly "int" under Posix-style systems.

More information about primitive data types can be found in the related links below

What Lead to C C plus plus and java?

(C and Lisp, ... data type") was adopted by many later languages, such as ALGOL 68 (1970), Java, and C#. ... C++ has a separate Boolean data type ( 'bool' ), but with automatic conversions from ... "Report on the Algorithmic Language ALGOL 68

Write a program of pyramid to print 12345678910?

output will

1

12

123

1234

12345

//mycfiles.wordpress.com #include

#include

void main()

{

int i,j;

clrscr();

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

{

printf("\n");

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

printf("%d",j);

}

getch();

}

To reverse the output

12345

1234

123

12

1

//mycfiles.wordpress.com

#include

#include

void main()

{

int i,j;

clrscr();

for(i=5;i>=1;i-)

{

printf("\n");

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

printf("%d",j);

}

getch();

}

improved::::::

#include

#include

#include

void main()

{

int i,j,k;

printf("Please enter your desired value:");

scanf("%d",&k);

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

{

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

printf("%d",j);

printf("\n");

}

printf("Press any key to close.");

getch();

}

What is the meaning of 2L in C programming?

2L is the literal constant for a long (int) type with the value 2.

In programming with C Write a program to find the age of the eldest and youngest person in a family maximum of 10 persons. It reads the ages of all the members of a family stores them in an array and?

#include using namespace std;int main() { int age[10]; int num=1;cout<<"How many persons are there in list ? "; cin>>num; for(int x=0; x { cout<<"Enter person"< cin>>age[x]; } int eldest = age[0]; int young = age[0]; for(int y=1; y < num; y++) { if(age[y] > eldest) { eldest = age[y]; } if(age[y] < young) {young = age[y]; } } cout<<"Age of eldest person is "<cout<<"Age of youngest person is "< return 0; }#include using namespace std; int main() { int age[10]; int num=1;cout<<"How many persons are there in list ? "; cin>>num; for(int x=0; x { cout<<"Enter person"< cin>>age[x]; } int eldest = age[0]; int young = age[0]; for(int y=1; y < num; y++) { if(age[y] > eldest) { eldest = age[y]; } if(age[y] < young) {young = age[y]; } } cout<<"Age of eldest person is "<cout<<"Age of youngest person is "< return 0; }