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

How the array has to be declared and initialized?

An example might help

int myarray [] = {2,0,1,3,1,1,2,9};

What Is The Difference Between Control and Uncontrolled statements?

ctrl statements ctrl the flow of pgrm execution with the given condisn but ctrl transfer statemens causes the change in pgrm flow without any condisn....

What are the attributes of good programming languages?

There are many attributes that make up a good programming language. Here are some of the most important ones:

Readability: A good programming language should be easy to read and understand. This makes it easier for developers to write and maintain code, and reduces the likelihood of errors.

Maintainability: A good programming language should be easy to maintain and update. This includes having clear and concise syntax, as well as tools for debugging and testing.

Performance: A good programming language should be efficient and fast. This includes having a low memory footprint, minimal overhead, and fast execution times.

Portability: A good programming language should be portable, meaning it can run on different platforms and operating systems without significant changes.

Flexibility: A good programming language should be flexible enough to accommodate different programming styles and paradigms, as well as be extensible with libraries and frameworks.

Safety: A good programming language should prioritize safety and prevent common programming errors, such as null pointer dereferences or buffer overflows.

Community: A good programming language should have a supportive and active community of developers who contribute to its development, documentation, and maintenance.

Tooling: A good programming language should have a robust ecosystem of tools, such as editors, IDEs, and build systems, that make development and deployment easier and more efficient.

Scalability: A good programming language should be able to scale with the needs of the project, whether it be a small script or a large-scale enterprise application.

Future-proofing: A good programming language should be designed with a long-term vision, taking into account future developments in hardware, software, and technology trends.

List two types of errors that can lead to an infinite loop?

Quite simply: a circular function in the programming, not going anywhere.

Why don't you directly specify the number of bytes to reserve to store data in memory?

You don't directly specify the number of bytes to reserve in memory to store data because you don't necessarily know how many bytes that data requires.

Instead, you specify the type of data and the number of elements, and the compiler and run-time library figures out how many bytes to allocate.

Its a portability issue. You don't want to tie your code to a specific word size because the code would then break when the underlying platform changes. One very famous example of this is the int data type in MS Windows 3.x. That was a 16-bit integer. When Windows "grew up" and the int became a 32-bit integer, the int changed to 32-bit, and everyone's code broke, except those that planned ahead and wrote the code correctly.

How do you convert decimal number to binary number using while loop?

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

long int a[20],i,n,count=0,b[20],c[20],sum=0;

printf("ENter the number in binary form=\t");

scanf("%ld",&n); // Get a binary number from the user

for (i=0;n>=1;i++)

{

a[i]=n%10;

n=n/10; // Loop To reverse the number And put all reversed numbers in arry a[i]

count=count + 1; // count to count the number of times this loop runs

}

for (i=0;i<=count-1;i++) // count -1 condition is used to run the loop till the previous loop run

{

b[i]=pow(2,i); // This is to raise the power of 2 to no of times previous loop runned.

}

for (i=0;i<=count-1;i++)

{

c[i]=a[i] * b[i]; // Multiply a[i] or reveresed binary no with b[i] or increasing pow of 2 to count-1

sum=sum +c[i]; // it is to add the c[i] elements with each other n put into sum variable.

}

printf("Decimal form =%ld",sum); // printing the sum to get the decimal form

getch();

}

// Hope it solves your problem, ANy more assistance honey.gupta13@yahoo.com ffffff

Why do you need signed and unsigned integer?

We need signed integers in order to represent both negative and positive values. However, some numbers can never be negative. For instance, the size of a file must always be greater than or equal to zero so we use unsigned integers to represent file sizes. Also, natural numbers must be greater than 0 so there's no point in using a signed value to represent a natural number. Signed integers also use one bit to denote the sign, but unsigned integers do not thus unsigned integers can effectively represent twice the range of positive values than an unsigned integer can. For instance, an 8-bit signed value can represent values in the range -128 to +127 using twos complement notation, but an 8-bit signed value can represent values in the range 0 to 255.

Write a C program to print numbers from 1 to 999 in words?

write a c program which reads an integer value from the keyboard then it displays the number in words?

#include<stdio.h>

#include<conio.h>

void main(void)

{

int rev,n,

clrscr();

printf("\n enter any number");

scanf("%d",&n);

temp=n;

while(n>0)

{

rem=temp%10;

rev+=rem*10;

temp=temp/10;

choice=rev%10;

switch(choice)

{

case 1:

printf("one");

break;

case 2:

printf("two");

break;

case 3:

printf("three");

break;

case 4:

printf("four");

break;

case 5:

print("five");

break;

case 6:

printf("six");

break;

case 7:

printf("seven");

break:

case 8:

printf("eight");

break:

case 9:

printf("nine");

}

getch();

}

What are the unique advantages of object oriented programming paradigm?

a. OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.


b. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.


c. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

What is difference between c and pro c?

C is the computer language bases on K&R's language that has evolved over the years. It includes C++, as extended by Stroustroup..

Pro*C is an Oracle precompiler that will read a C or C++ program, detect Oracle extensions to it, and convert it to native code for subsequent processing by the C or C++ compiler. This involves building the data structures and function calls needed to use Oracle while passing the non-Oracle C or C++ code through intact. The amalgamated code is then processed by the C or C++ compiler and it now works with Oracle.

What is an example of a pretest loop?

Well, from my knowledge of pseudocode, a pre-test loop contains the DO WHILE and LOOP functions.

So say you want to pour some milk into your cereal for breakfast:

DO WHILE cereal_bowl.Full = False

Pour_Milk

LOOP

Basically this is you saying, I am going to pour milk WHILE the bowl is not full. Once the bowl is full you will stop because you checked before your poured (a pre-test).

Hope this helps.

- The Doctor

What is Objectives Oriented Evaluation Approach to program evaluation?

Objectives Oriented Evaluation Approach is the means by which the worth or merit of a program is assessed based on the extent to which the objectives or purposes of the program are being achieved.

When to use Inheritance in C?

Assume the question was for C#, not C.

":" is syntax to extend a type. If the type extended from is another class, they form a class hierarchy and the "inheritance" is established:

For example:

class Base {}
class Derived : Base {}

Derived extends Base, and thus inherits from Base.


How do you empty a file using C programming?

That depends on the type of file and what you mean by "empty". Generally, fopen() called on an existing file, with the "w" option instead of the "a" option will truncate the file to zero length. To delete a file completely is a different process. Function truncate is your friend.

Can a structure be assigned to another using assignment operator?

Yes, provided both structures are of the same type:

struct S {/*...*/};

S a, b;

// ...

a = b;

The built-in structure assignment operator is typically implemented as a memory copy (memcpy) operation as this is the most efficient means of performing member-wise copy, as opposed to performing individual assignment operations upon each member.

Be aware that pointer members are shallow-copied not deep-copied:

struct S {

void* ptr;

size_t size;

};

S a;

a.size = 100 * sizeof(int); // allow for storage of 100 integers

a.ptr = malloc (a.size); // allocate memory

At this point, object 'a' owns the memory allocated to a.ptr.

S b;

b = a;

At this point, ownership of the memory is ambiguous because both a.ptr and b.ptr are referring to the same memory address. Shared memory is best avoided because releasing that memory will invalidate all objects that share the same memory:

free (a.ptr);

free (b.ptr); // Undefined behaviour: releasing the same memory twice!

To avoid this, we must manually perform a deep-copy:

S b;

b.size = a.size; // copy the size member

b.ptr = malloc (b.size); // allocate new memory

memcpy (b.ptr, a.ptr, a.size); // deep-copy

Note that the onus is entirely upon the programmer to ensure resource ownership is unambiguous. The compiler cannot help you.

In object oriented languages like C++, we use "smart" pointers (resource handles) rather than "naked" pointers. In this way, the onus of resource ownership shifts to the language itself.

Why should a function that accepts an array as an argument and processes that array also accept an argument specifying the array?

Basically in c++ passing an array as an argument only provides a pointer to the first value and that function won't know how many values it has.

If you read beyond the size you will just get garbage from memory.

What is the Advantages of selection sort?

+ reasonable fast in worst and average cases, n lg n + O(n)

+ in place

- best case still n lg n

How can the value of an expression be converted to a different data type in c?

There are different ways, there is one straight forward though. For instance you have a variable of type char: var1. And you want to convert it to another variable of type int: var2. You can use casting for it:

var2 = (int) var1;

You have to be very careful using casting because it cause buffer overflow. Newer versions of C have many different function to assure correctness of parsing, for instance, TryToParse...

Can a function be called from more than one place in a program in c plus plus?

In C and C++, as well as in many (all?) languages, a function can be called from more than one place in a program. That's the purpose of functions - to encapsulate pieces of code that are needed in more than one place in the program.

What is complete binary tree in c?

The basic idea (you write functions CountChildren, GetChild, NewBinTree):

struct GenTree;

struct BinTree;

typedef struct GenTree GenTree;

typedef struct BinTree BinTree;

int CountChildren (const GenTree *from);

int GetChild (const GenTree *from, int which);

BinTree *NewBinTree (DATATYPE data, BinTree *left, BinTree *right);

BinTree *Convert (const GenTree *from)

{

BinTree *bt, *tmp;

int i, n;

if (from==NULL) return NULL;

n = CountChildren (from);

bt = NewBinTree (from->data, NULL, NULL);

if (n 1) return bt;

tmp = Convert (GetChild (from, n));

for (i=n-1; i<=2; --i) {

tmp= NewBinTree (<NODATA>, Convert (GetChild (from, i)), tmp);

}

bt->right = tmp;

return bt;

}

Explain the scope and visibility of variables in c plus plus function?

If you define a variable inside of your function, the variable can be referred and used only inside of that function. It means that you will not able to use the variable in another function (including main). Area of code where your variable can be used after declaration is usually called visibility of the variable.

What is the difference between data record and data base?

A data record is a collection of various fields of data (like name, organisation, sex, age etc), whereas a database is a collection of records tables. (And views, indexes, stored procedures, and other stuff;)

Describe the four basic data types in c?

Describe the basic data types in C

Describe the basic data types in C

How is C program portable?

Your program is portable if you can compile and execute it on different platforms.