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

C program To sort a string in ascending order?

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

int i,j,d;

char ch[20],temp;

clrscr();

printf("\nEnter the no.of string:");

scanf("%d",&d);

printf("\nEnter the strings:");

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

{

gets(ch[i])

}

printf("\nThe strings are:");

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

{

printf("\n%s",ch[i]);

}

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

{

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

if(ch[i]>ch[j])

{

temp=ch[i];

ch[i]=ch[j];

ch[i]=temp;

}

}

getch();

}

What is style of function is not obsolete in c language?

Old:

function (par1, par2)

int par1;

char *par2;

{...}

New:

int function (int par1, char *par2)

{...}

Difference between do while and for loop?

for loop it consists of 3 parts 1. initialization 2. condition 3. incrementation like

for(i=1;i<=10;i++).This loop executes 10 times.

While loop: This is an entry check loop. First it checks for the condition and if the condition is true then only loop will be executed and this continues till the condition becomes false.

ex: i=0;

while(i<10)

{i++;

} This loop executes 10 times.

Do loop: This is an exit check loop. This executes the loop at least once even when the condition is false.

ex: 1=0;

do

{

i++;

}while(i<10);

What is meant by GB data?

GB is acronym for gigabyte and is used to indicate storage capacity on a computer. A gigabyte is 2^30 bytes or 1,073,741,824 bytes.

Note that disk manufacturers and memory chip manufacturers use different notations. Memory chips are precisely specified such that a 1 GB memory chip is guaranteed to provide storage for exactly 1,073,741,824 bytes. However, hard drives only give approximate storage capacities such that 1 GB only guarantees storage capacity for at least 10^9 bytes, or 1 billion bytes, which is the equivalent of a 0.93 GB memory chip.

Technically, hard-drive manufacturers use the correct notation since the prefixes kilo-, mega- and giga- literally equate to some power-of-ten (10^3, 10^6 and 10^9 respectively). However, it is not possible to create a memory chip with exactly 10^3 bytes, it has to be an exact power-of-two (2^10, 2^20 and 2^30, respectively).

The reason memory has to be an exact power-of-two stems from the way in which memory is addressed on a binary computer. In order to address 1000 bytes we'd need at least 10 bits in the range 0000000000 through 1111100111 (0 to 999 decimal) which means there are 24 invalid addresses in the range 1111101000 through 1111111111 (1000 to 1023 decimal). This over-complicates circuit design; it's much easier to make all bit patterns valid by adding on those missing 24 addresses thus giving us the full kilo-binary-byte capacity of 1024 bytes. Hard-drive manufacturers are less constrained in the way storage is addressed, because the addressing is subject to the operating system and the way in which the hard-drive is formatted. Typically, a hard-drive is divided up into addressable clusters which are themselves some power-of-two bytes in length, such as clusters of 512, 1024, 2048 or 4096 bytes.

In an effort to avoid confusion, the terms kilo-binary-byte (KiB), mega-binary-byte (MiB) and giga-binary-byte (GiB) are used to indicate precise memory capacities while KB, MB and GB are used to indicate the more generalised hard disk capacities. However, these terms is not widely adopted. For instance, Windows operating systems use the term KB to mean 1024 bytes whether reporting memory capacity or hard drive capacity, hence a 300 GB hard-drive only has capacity for 279.4 GB of storage on Windows. But 279.4 GB is 300 billion bytes so, strictly-speaking, it is quite correct to call it a 300 gigabyte drive.

What is branching in C?

Branching in 'C' (or any other programming language) is where the flow of execution of code can change depending on some test condition. In 'C', this can be achieved with the "if" statement or the "switch" statement:

void branching (int i)

{

if ( i < 10) {

// Branch 1 - less than 10

printf("i is less than 10");

}

else {

// Branch 2 - 10 or more

printf("i is greater than or equal to 10");

}

}

How do you write a computer program to arrange numbers in ascending order?

#include

int main()
{
int num[100];
printf("please input your numbers.enter any letter for the end\n");
int i=0,j=0,k=0;
while(scanf("%d",&num[i++]));
i--;
printf("you input %d numbers\n",i);
for(j=i-1;j>=0;j--){
for(k=0;k<=j;k++){
if(num[k]>num[k+1]){
int temp;
temp=num[k+1];
num[k+1]=num[k];
num[k]=temp;
}
}
}
for(j=0;j<=i-1;j++){
if(j%5)
printf("%d ",num[j]);
else{
printf("\n");
printf("%d ",num[j]);
}
}
return 0;
}

Example of utility?

Utility programs are non-applications. Applications allow you to work productively with your computer (MSWord, Excel, etc). Utility programs allow you to configure, diagnose, repair or monitor computer activity. Examples of utility programs are SCANDISK (to repair partitions) and FORMAT (to configure partitions). Control Panel applets are also utilities.

5 Why Searching is slower in Linked-List than in Trees?

Searching is slower for linked-lists rather than (ordered) trees because you need to iterate through each element serially, whereas for an ordered (binary) tree you use a "divide and conquer", otherwise known as binary search, method.

Think of it this way. Think of a number between 1 and 128. Perhaps the number is 97. With an ordered list, it would take 97 comparisons to find the item. With an unordered list, it would take an average of 64 comparisons - if the order was random. With a binary tree, i.e. a binary search, you only need 7 comparisons. In fact, you never need more than 7 comparisions for a tree size of 128, and on average, you would use less than that.

Where is the memory allocated?

Cache memory is built into the central processing unit, commonly known in short as the CPU, or it can be located on a separate chip next to the CPU.

In other sense, cache is located between CPU and Main Memory in the memory hierarchy of a computer system.

just type allinurl:cache memory, in Google search and you will find your answer with more pictures and a lot more about cache memory.

How do you write a program to find whether the given number is prime or not and show output?

#include<stdio.h>

#include<conio.h>

void main()

{

int n,a=2;

clrscr();

printf("\n enter n");

scanf("%d",&n);

if(i<=a-1)

{

if(a%i==0)

{

printf("\n the given number is not a prime number");

break;

}

i++;

if(a==i)

{

printf("\n the given number is a prime number");

}

getch();

output:

enter the value of n:2

the given number is prime number

How do you print the following pattern in C language X X X X X X X X X?

There are a few ways of going about this. The easiest way would be through a literal string:

printf("X X X X X X X X X");

If you want to print an arbitrary number of X's (in this case, 9), a for() loop would work:

for (count=0; count<9; count++) printf("X ");

This code would generate a final space at the end. To fix this and only use spaces to separate X's:

for (count=0; count<9; count++) printf("%sX", count?" ":"");

What is substr function does in c?

it will give the substring of length(as per the user) from the actual string,and the starting length from where it has to copy the substring from actual should be given by the user.

Which part of the for loop is resposible for assigning a value to a variable?

Typically, the variable is initialized in the first clause of the for statement, and incremented in the third clause. However, the language does not require any particular type of statement in these places.

The following is a typical example:

for (int i=0; i

In this example, the variable i is initialized in the first clause, and incremented in the third.

The same effect could be realized by putting the initialization and increment in other places:

int i=0; for (/* */; i++ /* */)

but this would be more difficult to read.

What is database design?

Design of the database (Database Design) refers to a given application environment, optimize the structure of the database, the database and applications, which can efficiently store data to meet the application needs of various user information needs and processing requirements). At www. myelibrary.net.In you can clearly understand what is the database design.

Advantages of having no type in a language?

A type system is generally very useful. It prevents you from making many mistakes. For example adding 1 to "cool" would result in a garbage answer but you might do it accidentally without types.

However types are sometimes constraining and inflexible. Perhaps I really do want to add 1 to 'c' because I know exactly what new ascii value it would give me. Type systems also increase compile time, run time, or both.

Note: You may be confusing no typing with dynamic typing. With dynamic typing you generally do not label a variable with a type in its declaration. Scripting languages like python are often like this. However they remain strongly typed languages. Assembly is an example of a untyped or one type language.

Where are global variables tored?

In a segment of memory, whose name is 'data segment'

One instruction in high level language corresponds to one instruction in machine language?

No. Generally, one instruction in a high level language corresponds to many instructions in machine language.

What complications are imposed if one tries to implement a dynamic list using a traditional homogeneous array?

in dynamic list after adding a new element size of the list disturbed so deletion and insertation is necessary to add a new element

Explain the four basic data type in C. What is the size in byte of each type in DOS and UNIX platforms?

1. 'Explain' is not a question, but here you are:

unsigned char: a number between 0 and 255

signed char: a number between -128 and 127

unsigned short: a number between 0 and 65535

signed short: a number between -32768 and 32767

2. sizeof (type) will tell you

Write a program in C?

Yes, please do. Here is an example:

#include <stdio.h>

int main (void)

{ puts ("Hello, World"); return 0; }

Advantages of multiple inheritance in UML?

dvantages of multiple inheritances:
· Multiple inheritance allows a class to inherit the functionality of more than one base class thus allowing for modeling of complex relationships


· You categorize classes in many ways. Multiple inheritance is a way of showing our natural tendency to organize the world. During analysis, for example, we use multiple inheritance to capture the way users classify objects.


· By having multiple super-classes, your subclass has more opportunities to reuse the inherited attributes and operations of the super-classes.


Disadvantages of multiple inheritances:
· Some programming languages (such as Java) do not allow you to use multiple inheritances. You must translate multiple inheritance into single inheritance or individual java interfaces. This can be confusing and difficult to maintain because the implemented code for categorizing objects is quite different fro the way the user organizes those objects. So, when the user changes their mind or adds another category, it is difficult to figure out how to program the new sub classes.


· The more super classes your sub class inherits from the more maintenance you are likely to perform. If one of the super classes happens to change, the sub class may have to change as well.


· When a single sub class inherits the same attribute or operation form different super classes, you must choose exactly which one it must use.


Multiple inheritances can cause a lot of confusion, say when both the classes from which you want the child class to inherit from, has a method with same


Muhammad Shahbaz


Linux Administrator




Other Responses:


The Eiffel language and method was designed from the ground up to have multiple inheritance without ANY of the `gotchas' of languages like Java, C++ and others. The `disadvantages' listed above have nothing to do with MI, but with the technique and technologies listed (e.g. Java or C++). When MI is designed thoughtfully into a language and method, then the `dangers' or `disadvantages' are not there. As an Eiffel engineer, we use MI extensively, safely and beneficially all the time.