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 remove error unable to open the file stdio.h in c?

Reinstall C or update the C library function . stdio.h must be missing

Why write programs in machine code?

The resulting programs are more efficient, use less processor cycles and memory. Because michine code is the most basic form of language that a processor can understand. It consists of 1's and 0's. It needs no interpreter to interpret to the processor and therefore is the fastest way to tell a processor which commands to run.

C program to check a for loop syntax?

//PROGRAM TO CHECK SYNTAX OF for STATEMENT

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<process.h>

void main()

{

FILE *fp1,*fp2;

char a[100],ch,b[50];

int col=0,i=0,bra1=0,bra2=0,flag=0;

clrscr();

fp1=fopen("c:\\file1.txt","w");

if(fp1==NULL)

{

printf("\n ERROR IN OPENING FILE ... ");

getch();

exit(0);

}

else

{

printf("\n ENTER THE for STATEMENT ... ");

gets(a);

fprintf(fp1,"%s",a);

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

b[i]=a[i];

b[i]=0;

if(strcmp(b,"for")!=0)

{

printf("\n ERROR: UNDEFINED SYMBOL for ");

getch();

exit(0);

}

if(a[i]=='(')

flag=1;

else

flag=0;

fclose(fp1);

fp1=fopen("c:\\file1.txt","r");

while(1)

{

ch=getc(fp1);

if(ch==EOF)

break;

else if(ch=='(')

bra1++;

else if(ch==')')

bra2++;

else if(ch==';')

col++;

}

if(flag==0)

printf("\n ERROR: UNDEFINED SYMBOL for ");

else if(bra1!=1)

printf("\n ERROR: BRACKET ERROR '(' ");

else if(bra2!=1)

printf("\n ERROR: BRACKET ERROR ')' ");

else if(col!=2)

printf("\n ERROR: SEMICOLON ERROR ';' ");

else

printf("\n NO ERROR: ");

}

fclose(fp1);

getch();

}

What is Realloc?

This involves allocating and de-allocating memory at run-time. Look into the new and delete operators for C++ or malloc and free for C.

Example of semantic errors?

scores = [51, 47, 53, 97, 27]

summation = 0.0

for score in scores:

summation *= score # Semantic Error.

average = summation / len(scores)

print average # Isn't average. average == 0

What are unconditional statements?

An unconditional statement is one which would happen always (unconditionally).

Conditional statement:

if(x > 5)

print "Hello!"

Unconditional statement:

print "Hello!"

This term also comes up when speaking of assembly instructions. An unconditional jump would be a line of assembly which always executes the jump. This is in contrast to a conditional jump (also known as a branch) which will execute the jump only if some statement evaluates to true.

What is the strcpy function?

The strcpy function is declared in the <string.h> header of the C standard library. The function is used to copy a null-terminated string (a null-terminated array of type char). The function accepts two arguments: a pointer to the memory allocation where the copy will be placed; and a pointer to the first character of the null-terminated string to be copied. The memory allocation where the copy will be made must be large enough to accommodate the string, including the null-terminator.

Example usage:

void f (char* s) {

int len;

char* c;

len = strlen (s) + 1; /* determine length of string (including null-terminator) */

c = malloc (len); /* allocate memory for copy */

strcpy (c, s);

/* ... */

free (c); /* release allocation */

}

Why c is called partially an OOP language?

C is not an OOP language, period. However, while C++ supports OOP it does not rely on it. With C++, you can mix procedural, structured and object-oriented principals by mixing C++ code with C-style code and even raw assembly routines, neither of which are object-oriented.

How can you calculate your age using turbo c?

It will be something like this:

int birthyear = 2001; /* replace it with your birthyear */

int age = 2011 - birthyear;

C program to check whether a given matrix is orthogonal or not?

#include<iostream>

#include<stdio.h>

#include<conio.h>

using namespace std;

int main()

{

int a[20][20],b[20][20],c[20][20],i,j,k,m,n,f;

cout << "Input row and column of A matrix \n\n";

cin >> n >> m;

cout << "\n\nInput A - matrix \n\n";

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

for(j=0;j<m;++j)

cin >> a[i][j];

cout << "\n\nMatrix A : \n\n";

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

{

for(j=0;j<m;++j)

cout << a[i][j] << " ";

cout << "\n\n";

}

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

for(j=0;j<n;++j)

b[i][j]=a[j][i];

cout << "\n\nTranspose of matrix A is : \n\n";

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

{

for(j=0;j<n;++j)

cout << b[i][j] << " ";

cout << "\n\n";

}

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

{

for(j=0;j<m;j++){

c[i][j]=0;

for(k=0;k<=m;k++)

c[i][j]+=a[i][k]*b[k][j];

}

}

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

{

for(j=0;j<m;j++)

{

if((int)c[i][i]==1&&(int)c[i][j]==0)

f=1;

}

}

cout<<"\n\n Matrix A * transpose of A \n\n";

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

{

for(j=0;j<m;j++)

cout << c[i][j];

cout << "\n\n";

}

if(f==1)

cout << "\n\nMatrix A is Orthogonal !!!";

else

cout << "\n\nMatrix A is NOT Orthogonal !!!";

getch();

return 0;

}

-ALOK

What is the difference between int and int32?

The size (and value-range) of int is platform-dependent, whilst that of int32_t is fixed.

What is an interrupt and how are multiple interrupts dealt with?

An Interrupt is a signal that goes into a microprocessor that tells it something has happened that needs attention. There are generally dedicated pins on the microprocessor, often called "Int" (for Interrupt) and "NMI" (for Non-Maskable Interrupt). For a microprocessor, an interrupt signal is like the bell on a telephone is for you; it's a notice that you should stop what you are doing now and deal with this issue that has come up.

Exact procedures for dealing with an interrupt vary from one microprocessor to another; generally, the microprocessor puts out a signal that says "Where should I go, then?" and a piece of hardware, the Interrupt Controller, then responds with a signal that tells it which condition has happened. The processor then starts processing the indicated piece of code, and that piece of code handles the condition.

The Interrupt Controller often handles setting priority for interrupts, accepting a number of signals (often four), and setting priorities on each. It will trigger another interrupt in the middle of processing one if the new interrupt is a higher priority than the one that is already being processed, or will hold on to the lower priority one until the CPU is finished with a higher-priority one.

The CPU can often "disable interrupts" when it is doing something time-critical. At such times, the only interrupt that can occur is the Non-Maskable Interrupt, which is generally reserved for critical error conditions that have to be dealt with immediately no matter what else is going on.

What are the uses of array?

Array in most programming langauges like C ,C++, Java etc is a static , homogeneous and linear data structure. A data structure itself is a mathematical and logical model to organise data.It clearly specifies the domain of the data that can be stored in the structure and the collection of valid operations (functions) that can be performed on that data. Array is a linear structure in the sense that the data is organised sequentially(one after another in a contineous chunck of memory). It is a homogeneous data structure i.e. it contains elements which are of the same data type.The data type of array can be inbuilt like int , float ,char, double and even user defined that is created using a structure or a class. The main use of an array is to oragnise homogeneous data together as a group to perform operations on data in a collective manner since traversal and retrieval becomes easy.Whenever a homogeneous list(One Dimendional or Multi-Dimensional)has to be implemented we make use of array.The advantage of array lies in the fact that it uses indexed represenattion enabling us to access any member element directly. The example of practical use of array in progarmming will be creation of index lists, pointer arrays,matrix operations(transpose,addition ,subtraction,multiplication,inverse etc.).

How do you evaluate a expression?

Replace all the variables in the expression by their numerical values and calculate the result.