Programming Questions

Q:

Which error are you likely to get when you run the following program?

main()

{

  struct emp

  {

      char name[20];

      float sal;

  };

  struct emp e[10];

  int i;

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

        scanf ( "%s %f" , e[i].name, &e[i].sal );

}

Answer

Floating point formats not linked

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1733
Q:

What would be the output of the following program, if the array beigns at address 65486?

main()

{

    int arr[] = {12,14,15,23,45};

    printf ("%u %u", arr, &arr);

}

Answer

65486  65486

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1727
Q:

How would you find the length of each string in the following Program?

main()

{

    char *str[] = { "Frogs", "Do", "Not" , "Die" , "They" , "Croak!"};

    printf ("%d%d", sizeof (str), sizeof (str[0]));

}

Answer

main()


{


   char *str[] = { "Frogs", "Do", "Not", "Die." , "They", "Croak!" };


   int i;


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


         printf ("\n%s%d", str[i], strlen( str[i]));


}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 1724
Q:

What would be the output of the following program?

main()

{

    float a = 0.7;

    if ( a < 0.7f )

          printf ( " C ");

    else 

          Printf ( " C++ ");

}

Answer

C++

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1719
Q:

Swap two variables without using third variable.

Answer

#include<stdio.h>
int main(){
    int a=5,b=10;
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);
}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1711
Q:

In the following code in which order the functions would be called?

a = ( f1 ( 23,14 ) * f2 ( 12/4) ) + f3() ;

Answer

The order may vary from compiler to compiler.


Here the multiplication will happen before the addition , but in which order the functions would be called is undefined. In an arithmetic expression the parentheses tell the compiler which operands go with which operators but do not force the compiler to evaluate everything within the parentheses first.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1689
Q:

C program to find whether a number is palindrome or not.

Answer

 #include<stdio.h>
int main(){
    int num,r,sum=0,temp;

    printf("Enter a number: ");
    scanf("%d",&num);

    temp=num;
    while(num){
         r=num%10;
         num=num/10;
         sum=sum*10+r;
    }
    if(temp==sum)
         printf("%d is a palindrome",temp);
    else
         printf("%d is not a palindrome",temp);

    return 0;
}

Sample output:
Enter a number: 131
131 is a palindrome

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 1674
Q:

Write a c program to copy a data of file to other file.

Answer

#include<stdio.h>
int main(){
  FILE *p,*q;
  char file1[20],file2[20];
  char ch;
  printf("\nEnter the source file name to be copied:");
  gets(file1);
  p=fopen(file1,"r");
  if(p==NULL){
      printf("cannot open %s",file1);
      exit(0);
  }
  printf("\nEnter the destination file name:");
  gets(file2);
  q=fopen(file2,"w");
  if(q==NULL){
      printf("cannot open %s",file2);
      exit(0);
  }
  while((ch=getc(p))!=EOF)
      putc(ch,q);
  printf("\nCOMPLETED");
  fclose(p);
  fclose(q);
 return 0;
}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1673