Blogger Tips And Tricks|Latest Tips For Bloggers Free Backlinks

c programming language interview questions and with answers pdf download

C interview questions,C language interview questions,C interview questions and answers,C interview questions with answers,C language interview questions and answer,C programming interview questions,
C interview questions and answers pdf,C interview questions and answers pdf download,C interview questions for freshers and experienced,C programming language interview questions



C image



C Interview Questions:

1. What is the C-language?

       C is a general purpose programmaing language.It was developed by "Dennis Ritchie"  in 1972 at  bells laboratory.C is a procedural oriented programming.C is compiled language.

                       For more information  click here

2. What are the compilation steps in C?

       The compilation will be start from the main() function in the C program.
        Before start the compilation the compiler read the header file in our program.


          If you want to clear about the compilation steps click here

                                       The above Figure shows the compilations steps in C


 3. Is it possible to write the program without header file?
  
        Yes,It is possible because the file name is saved with ".c" extension (ahamad.c) it will be automatically included the header file.        .

         Eg:-     File name is ahamad.c
  
     Sample program:      
                                         main()
                                         {
                                              printf("Welcome to C");
                                          }

              The above program will compile without header file but don't forget to save with ".c" extension.

4. Swap the given numbers without using third variable?

                #include<stdio.h>
                 main()
                {
                        int a=5,b=10;

                              a = a+b;
                              b = a-b;
                              a =a-b;

                     printf("After swap the given number\n",a,b);

                 }

        Output :-
                           a = 10, b = 5 


 5. Find the ASCII value of the given character?

        #include<stdio.h>
         main()
         {
               char ch;

                 printf("Enter Character\n");
                 scanf("%c",&ch);

                    if((ch> = 'a') && (ch < = 'z') || (ch >=  'A') && (ch <= 'Z'))

                             printf("%d\n",ch);
          }

         Output:-
                            Enter character
                                  a
                                97
                         
     
 6. Find the given number is even or odd?

             #include<stdio.h>
             main()
             {
                  int n;
                  
                     printf("Enter number\n");
                     scanf("%d",&n);
    
                         if(n%2 == 0)
                           printf("Given number is Even\n");

                          else
                            printf("Given number is Odd\n");

                
             }   

        Output:-
                       1.  Enter number
                              22
                          Given number is Even
                       2. Enter number
                                    22                          
                            Given number is Odd


 7. Fabonacci series?

              Each number is the sum of two previous numbers.The below program is for the fabonacci series
                  using do-while loop.
                     
                                       Give the click to clear the fabonacci series

 




                          #include<stdio.h>
                          main()
                          {
                                 int f,s,t;
                                 
                                   printf("Enter numbers\n");
                                   scanf("%d %d",&f,&s);
           
                                            do
                                                {
                                                      t = f+s;
                                                       printf("%d\n",t);
                                                       f = s;
                                                       s = t;
                                                 }while(t <= 50)
                           }

             Output: -
                                 Enter numbers
                                     0 1
                                 1 2 3 5 8 13 21 34 55
                     

 8. Sum of the given numbers?

              Suppose we enter the number 1234,The sum of the 1234 is 1+2+3+4=10.
      Program is developed at below for this logic.

                   #include<stdio.h>
                   main()
                   {
                           int n,rem,sum=0;
 
                                printf("Enter the number\n");
                                scanf("%d",&n);

                                  while(n>0)
                                  {
                                        rem = n%10;
                                        sum = sum + rem;
                                         n = n/10;
                                   }
                           printf("After summing the numbers %d\n",sum);
                    }

              Output:-
                             
                                   Enter the number
                                       1234
                                    After summing the number 10
 

 9. Reverse the given number?

         This means exactly reverse the given number. Suppose the given number is 5678
          After Reverse the number 8765.

                                #include<stdio.h>
                                main()
                                {
                                       int n,rev=0,mod;

                                        printf("Enter number\n");
                                        scanf("%d",&n);

                                               while(n>0)
                                                {
                                                     mod = n%10;
                                                     rev = (rev*10)+mod;
                                                     n = n/10;
                                                 }
                                          printf("After Reverse the number  %d\n",rev);
                                 } 

          output:-
                              Enter the number
                                     5678
                              After Reverse the number 8765

 10. Find the factorial of given number?

             If you want more information about the factorial give the click here


      C - Bit operations:
        
11. Print the given number in binary format?


                #include<stdio.h>
                main()
                {
                      int n,pos;
    
                         printf("Enter number\n");
                         scanf("%d",&n);

                              for(pos=31;pos>=0;pos--)
                                 {
                                         if((n&(1<<pos))==0)
                                          printf("0");

                                          else
                                            printf("1");
                                  }
                }

       Output:-
                      Enter number
                             5
                       00000000000000000000000000000101

 12. Bit clear the given number?

                  #include<stdio.h>
                  main()
                  {
                           int n,pos;

                           printf("Enter numbers\n");
                           scanf("%d %d",&n,&pos);

                             n=n&(~(1<<pos));

                            printf("After bit clear : %d\n",n);
                  }

    Output:
                     Enter numbers
                          7
                         
                     After bit clear3

 13. Bitset the given number?

                  #include<stdio.h>
                  main()
                  {
                           int n,pos;

                           printf("Enter numbers\n");
                           scanf("%d %d",&n,&pos);

                             n=n|(1<<pos);

                            printf("After bitset : %d\n",n);
                  }

    Output:
                     Enter numbers
                          6
                          3 
                     After bitset 14

 14. Bit toggle the given number?

                  #include<stdio.h>
                  main()
                  {
                           int n,pos;

                           printf("Enter numbers\n");
                           scanf("%d %d",&n,&pos);

                             n=n^(1<<pos);

                            printf("After bit toggling : %d\n",n);
                  }

    Output:
                     Enter numbers
                          6
                          8 
                     After bit toggling 262



 15. Bit checking the given number?

                  #include<stdio.h>
                  main()
                  {
                           int n,pos;

                           printf("Enter numbers\n");
                           scanf("%d %d",&n,&pos);

                             n=n&(1<<pos);

                            printf("After bit checking : %d\n",n);
                  }

    Output:
                     Enter numbers
                          6
                          9 
                     After bit checking 0


  C-Shift operations:


        Left shift the given number?

                   #include<stdio.h>
                   main()
                   {
                         int n,ls;

                           printf("Enter number\n");
                           scanf("%d",&n);

                                ls = n << 1;

                            printf("After left shift : %d\n",ls);
                    }

          Output:
                       Enter the number
                             4
                        After left shift  8


    Right shift the given number?

                   #include<stdio.h>
                   main()
                   {
                         int n,ls;

                           printf("Enter number\n");
                           scanf("%d",&n);

                                ls = n >> 1;

                            printf("After Right shift : %d\n",ls);
                    }

          Output:
                       Enter the number
                              10
                        After Right shift 5


     
       C with Strings: 


      Find the length of the given string using pointers?

                            #include<stdio.h>
                            int stringlength(char *);

                            main()
                            {
                                  char source[100];
                                     int length;

                                    printf("Enter String\n");
                                    scanf("%[^\n]",source);

                                       length = stringlength(source);

                                      printf("The length of the string is : %d\n",length);
                             }
                             
                               int stringlength(char *str)

                              {
                                     int count = 0;
                            
                                          while(*str != '\0')

                                               {
                                                     *str++;
                                                       count++;
                                               }
                                   return count;
                               }

                 Output:
                               Enter String
                                 beonlyone
                                 The length of the string is : 9   


 
      Copy of the string using pointers?

                            #include<stdio.h>
                            void stringcopy(char *,char *);

                            main()
                            {
                                  char source[100],destination[100];

                                    printf("Enter String\n");
                                    scanf("%[^\n]",source);

                                       stringcopy(source,destination);

                                      printf("After copy the string is : %s\n",destination);
                             }
                             
                               void stringcopy(char *str1,char *str2)

                              {
                                                             
                                          while(*str1 != '\0')

                                               {
                                                     *str2 = *str1;
                                                     *str1++;
                                                      *str2++;
                                               }
                                     *str2 = '\0';
                               }

                 Output:
                               Enter String
                                 Welcome to C
                                After Copy the string : Welcome to C


    Reverse the string using pointers?

                            #include<stdio.h>
                            void stringReverse(char *);

                            main()
                            {
                                  char source[100];

                                    printf("Enter String\n");
                                    scanf("%[^\n]",source);

                                       stringReverse(source);

                                      printf("After Reverse the string is : %s\n",source);
                             }
                             
                               void stringReverse(char *str)

                              {
                                            int len = 0,i=0;
                                            len = strlen(str);
                                             char *t = str + len - 1;
                 
                                          while(i < len/2)

                                               {
                                                     char temp = *str;
                                                     *str = *t;
                                                      *t = temp;
                                                     *str++;
                                                      *t-- ;
                                                      i++;
                                               }
                               }

                 Output:
                               Enter String
                                 Hello World
                                After Reverse the string :dlroW olleH


  Find the sub-string in the main string?
  
                 See this video class for the good understanding of this concept.

                          


 
     C with memory functions:- 


     What is the memcpy() function?

             It copies the bytes of data between memory blocks or buffers.This function doesn't care about the
              type of data being copied.
                    It simply makes an exact byte for byte copy.

               Syntax:- 
                               void *memcpy(void *destination,void *source,size_t count);

                  #include<stdio.h>
                  #include<string.h>
                  main()
                  {
                        char str1[100] = "This is string";
                        char str2[100];

                          memcpy(str2,str1,14);

                        printf("str2 = %s\n",str2);
                  }

       Output:-
                        str2 = This is string

        If you will give the 10 at the count(14),it copies only 10 bytes.It gives the o/p is "This is st".
 
          
                 
       
                

Leave a Reply

Powered by Blogger.

Pages

Popular Posts

Search This Blog

Loading...

Blogger templates