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

Who can used to exit from a loop?

If you meant 'what can be used' then it is statement break.

Which program is what results when assembly language programs are converted to machine language using an assembler?

The result of assembling an assembly language source is an executable. The name of that executable is dependent upon the output file name passed to the assembler. The program that performs the assembly is the assembler itself.

More specifically, the assembler produces one or more object files, which are fed into the linker or binder. The linker or binder then produces the executable, by combining the object files, along with referenced library files, and then resolving external references.

Types of data in turbo C programming?

The primitive data types in C include:

  • [signed|unsigned] char
  • [signed|unsigned] short
  • [signed|unsigned] int
  • [signed|unsigned] long
  • [signed|unsigned] long long
  • float
  • double
  • long double

Enumerations (enum) and arrays may also be considered to be primitive types.

How do you create window with c?

It is not possible to create a window with C as the C language does not specify any standard libraries for doing graphical programming. It is possible to create a window with C and one of the many graphics libraries that have been written since C was created. For example, using the Gtk+ library: #include #include int main (int argc, char *argv[]) { GtkWidget *window; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show_all (window); gtk_main (); }

Write a c plus plus program of array to pointers?

#include
void

printarr(int

a[]);
void

printdetail(int

a[]);
main()
{
int

a[5];
for

(int

i = 0;i<5;i++)
{
a[i]=i;
}
printdetail(a);
}
void

printarr(int

a[])
{
for

(int

i = 0;i<5;i++)
{
printf("value in array %d\n"

,a[i]);
}
}
void

printdetail(int

a[])
{
for

(int

i = 0;i<5;i++)
{
printf("value in array %d and address is %8u\n"

,a[i],&a[i]);
}
}
void

print_usingptr(int

a[])
{
int

*b;

What condition linear search is better than binary search?

In linear search, the searched key will be compared with each element of the array from the beginning and terminate comparing when the searched key is found or the array is reached. Here time complexity in worst case and average case is O (n).

To find an element quickly we use divide and conquer method by using binary search algorithm. Here probed region is reduced from n to n/2. Time complexity is O (log2 n), but here the array should be sorted.

But in interpolation search the probed region is reduced from n to n1/2. If the array elements are uniformly distributed the average case complexity is O (log2 (log2n)).

Am also searching for hashing to compare & contrast with above.

How is a library file incorporated in a C program?

Every library requires a header file (.h file) that can be included in any translation unit that requires access to the library. The header describes the library interface. The library implementation may be provided by a corresponding .c source file in which case you can compile the library into your program just as you would any other translation unit. However, most library implementations are provided by a precompiled library file (.lib file) and you generally won't have access to the source file. The precompiled library file is required by the linker while the corresponding header is required by the compiler.

What is the pseudo code of radix sort in C?

step 1: Analyse the radix sort procedure first.

step 2:Convert the procedure in to the c coding

#include<stdio.h>

#define MAX 5

#define SHOWPASS

void print(int *a,int n)

{

int i;

for(i=0;i

printf("%d\t",a[i]);

}

void radixsort(int *a,int n)

{

int i,b[MAX],m=0,exp=1;

int bucket[10]={0};

for(i=0;i

{

if(a[i]>m)

m=a[i];

}

while(m/exp>0)

{

for(i=0;i

bucket[a[i]/exp%10]++;

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

bucket[i]+=bucket[i-1];

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

b[--bucket[a[i]/exp%10]]=a[i];

for(i=0;i

a[i]=b[i];

exp*=10;

#ifdef SHOWPASS

printf("\nPASS : ");

print(a,n);

#endif

}

}

int main()

{

int arr[MAX];

int i,n;

printf("Enter total elements (n < %d) : ",MAX);

scanf("%d",&n);

printf("Enter %d Elements : ",n);

for(i=0;i

scanf("%d",&arr[i]);

printf("\nARRAY : ");

print(&arr[0],n);

radixsort(&arr[0],n);

printf("\nSORTED : ");

print(&arr[0],n);

printf("\n");

return 0;

}

You can see the the same program with output in related links, below.

Can you use switch in string in c language?

"It's not just a good idea. It's the law!

In C, switch's and strings don't mix.

Use:

if (!strcmp(myval, "S1") {...}
else if (!strcmp(myval, "S2") {...}

etc"

--
ptrussell_nc
http://www.sqaforums.com/showflat.php?Cat=0&Number=473868&Main=473575


What must every c program have?

A main function must be present in every C program.

Can array be included as member of a structure?

Yes. Array elements can be any built-in type or user-defined type, including structures.

How do you create a two dimentional array?

A one-dimensional array is an array where each element in the array points to a specific value of the type specified by the array (all values must be of the same type). For example, we can store integer values in an integer array, character values in a character array and strings in a string array.

Multi-dimensional arrays are implemented as one-dimensional arrays where every element is itself a one-dimensional array, for as many dimensions as required. The overall size of any array (in elements) is the product of all its dimensions, thus a two-dimensional array of 4x5 elements has 20 elements in total, divided into 4 arrays of 5 elements each. However, because all the elements are allocate contiguously, any multi-dimensional array can be treated as if it were one-dimensional. Note that every element of an array must be exactly the same length, even when that element is another array.

The most common type of array we use is a pointer array (an array of pointer elements). Given that a non-null pointer does not store any size information (the number of elements being referred to), we typically use null-terminated pointer arrays, where a null pointer denotes the end of the array being referred to. This makes it possible to implement "jagged" or "irregular" multi-dimensional arrays, where each dimension can be a different length. An array of variable-length strings is an example of a jagged array, such that each element points to a null-terminated character array.

How do you find the nth number in a sequence?

tn = t1+(n-1)d -- for arithmetic

tn = t1rn-1 -- for geometric

Why does C plus plus allows static binding and not dynamic binding?

Dynamic binding, or late binding, is when the object code for the class does not get loaded into memory until it is needed. This saves time at module load time, at the cost of delayed execution for the first invocation.

What type of data is measured in numbers?

Quantitve observation (quality)... Qualitive observation involves the quality... THANKS MR. ENDRIS 2011

LJHS

Write a c program to reverse the string without using strrev?

#include<stdio.h>

#include<string.h>

void main()

{

char str[50],revstr[50];

int i=0,j=0;

clrscr();

printf("Enter the string to be reversed : ");

scanf("%s",str);

for(i=strlen(str)-1;i>=0;i--)

{

revstr[j]=str[i];

j++;

}

revstr[j]='\0';

printf("Input String : %s",str);

printf("\nOutput String : %s",revstr);

getch();

}

Does every c program ends with an END word?

No. All C programs end when the main function returns. C++ works the same way, however executions may continue after main returns while global and static objects are being destroyed. Objects in C do not have destructors so this is not a problem.

In multi-threaded applications in both C and C++, it is important that all worker threads are signalled to terminate by their controlling thread(s) before main returns.

What are the various rules for writing an identifier name in C language?

An identifier starts with one of [_, a-z, A-Z] and may continue with one or more of [_, a-z, A-Z, 0-9]. There are often length limitations as well as limitations involving leading underscores, [_], and identifiers may not exactly match any reserved word.

How do you write a program to test if a given number is divisible by 6 in C programming?

if ( x % 6 == 0 ){ printf( "%d is divisible by 6", x ); } else { printf( "%d is not divisible by 6", x ); }

How do you write a c program for performing file operations on student database?

#include<stdio.h>

#include<string.h>

#include<conio.h>

/*Structure created for student record*/

typedef struct student

{

int roll_no;

char name[30];

}student;

void copy(char [],char []);

/*Function to create or insert the records

In write mode it creates new file and write the records

In append mode it insert the records in already created file

*/

void create(char mode[])

{

student stud;

FILE *fp;

int total,i;

fp=fopen("Records.txt",mode);

if(fp==NULL)

printf("\nUnable to open the file");

else

{

printf("\nHow many record(s) do you want to enter\t");

scanf("%d",&total);

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

{

printf("Enter the roll no and name\t");

scanf("%d %s",&stud.roll_no,stud.name);

fprintf(fp,"\n\t%d \t%s",stud.roll_no,stud.name);

}

printf("\nRecord(s) inserted successfully...");

fclose(fp);

}

}

/*This function displays the record of file passed to it

using fread and fwrite*/

void display(char filename[])

{

student stud;

FILE *fp;

fp=fopen(filename,"r+");

if(fp==NULL)

printf("\nUnable to to open file");

else

{

while(fscanf(fp,"\n\t%d \t%s",&stud.roll_no,stud.name)!=EOF)

{

printf("\n%d\t%s",stud.roll_no,stud.name);

}

}

fclose(fp);

}

/*Function to search the records

It returns -1 if search is unsuccessful

else return 0*/

int search(int roll)

{

student stud;

FILE *fp;

fp=fopen("Records.txt","r+");

if(fp==NULL)

printf("\nUnable to to open file");

else

{

while(fscanf(fp,"\n\t%d \t%s",&stud.roll_no,stud.name)!=EOF)

{

if(roll 0)

printf("\n\tREnamed...\n\n");

//fclose(fp1);

printf("\n\nRecords deleted successfully...");

}

else

printf("\nOops! Record not found...");

}

}

/*Function to copy all records from one file to other*/

void copy(char f1[],char f2[])

{

student stud;

FILE *fp1,*fp2;

fp1=fopen(f1,"r+");

fp2=fopen(f2,"w+");

if(fp1==NULL fp2==NULL)

printf("\nUnable to to open file");

else

{

while(fscanf(fp1,"\n\t%d \t%s",&stud.roll_no,stud.name)!=EOF)

{

fprintf(fp2,"\n\t%d \t%s",stud.roll_no,stud.name);

}

fclose(fp1);

fclose(fp2);

printf("\n\nRecords copied successfully...");

printf("\nContents are...\n");

display(f2);

}

}

FILE *fp;

/*Main function starts*/

void main()

{

int ch,i,roll;

//if(!(fp=fopen("record.txt","r+")))

//fp=fopen("Record.txt","w+");

do

{

clrscr();

/*Menu for the function*/

printf("\n*** MENU ***");

printf("\n1.Create");

printf("\n2.Insert");

printf("\n3.Update");

printf("\n4.Search");

printf("\n5.Display");

printf("\n6.Copy");

printf("\n7.Delete");

printf("\n8.Exit");

printf("\nEnter your choice\t");

scanf("%d",&ch);

switch(ch)

{

case 1:create("w+");break;

case 2:create("a+");break;

case 3:modify();break;

case 4:

printf("\nEnter the roll no to be searched\t");

scanf("%d",&roll);

i=search(roll);

if(i==-1)

printf("\nOops! Record not found");

break;

case 5:display("Records.txt");break;

case 6:copy("Records.txt","Newcopy.txt");break;

case 7:Delete();break;

case 8:break;

default:printf("\nPlease enter proper choice...");

}

getch();

}while(ch!=8); /*Program terminates on choice 8*/

}

Written by: Fabianski Benjamin

What is the main feature in object oriented programming?

[Eating] A Pie:

Abstraction: grouping some data and behaviors into a programming unit with semantic similarity (not randomly), e.g, class, struct

Polymorphism: different object with the same name (same name of a method, variable, but in more than 1 form)

Inheritance: the most important characteristics of an OO language (Object base language would not have this one). It allows a derived class to inherit the data and behaviors from the base class(es), as if those data and behaviors are defined within.

Encapsulation: or information hiding. Object has data members that no one outside of the same class would know what type or shape they are. It also applied to the behaviors.

Are upper and lower case equivalent to C?

It is false. C is a case-sensitive language, so VALUE, Value and value are all treated as being different identifiers. By convention, all C standard library names are in lowercase and macro names are in uppercase. User-defined names typically begin with a leading capital.

Write a program in c plus plus to create an analog and digital clock using computer graphics?

#include "stdio.h"

#include "conio.h"

#include "dos.h"

void main()

{

int h,m,s;

h=0;

m=0;

s=0;

while(1)

{

if(s>59)

{

m=m+1;

s=0;

}

if(m>59)

{

h=h+1;

m=0;

}

if(h>11)

{

h=0;

m=0;

s=0;

}

delay(1000);

s=s+1;

clrscr();

printf("\n DIGITAL CLOCK");

printf("\n HOUR:MINUTE:SECOND");

printf("\n%d:%d:%d",h,m,s);

}

getch();

}