Subscribe:Posts Comments | Read Articles on Various Topics - Pro Articles

By PDMACpayday loans

You Are Here: Home » C and C++, Technical Interview Questions » C++ and C Language Exam Technical problems

C and C++ Technical Written test / technical interview questions:

See more programming, software development questions for IT Companies placement papers held in India, US, UK, Germany, France, Italy, Japan, China and other places. Must see real candidate interview experiences. Top C and C++ Questions asked in IT Technical Interviews.

  1. How come the output for both the programs is different when the logic is same?
    main( )
    {
    int i, j ;
    for ( i = 1, j = 1 ; i <= 5, j <= 100 ; i++, j++ )
    {
    gotoxy ( 1, 1, ) ;
    printf ( “%d %d”, i, j ) ;
    }
    }
    main( )
    {
    int i, j ;

    for ( i =1, j = 1; j <= 100, i <= 5; i++, j++ )
    {
    gotoxy ( 1, 1 ) ;
    printf ( “%d %d”, i, j ) ;
    }
    }
    Output -> 5 5
    Even if logic of both the programs is same the output of the first program comes out to be 100, 100, but of the second program it is 5, 5. The comma operator plays a vital role inside the for loop. It always considers the value of the latest variable. So, at the time of testing the condition in for loop, the value of j will be considered in the first program and value of i in the second.

  2. Can we get the x and y coordinate of the current cursor position ?
    Ans : The function wherex( ) and wherey( ) returns the x-coordinate and y-coordinate of the current cursor position respectively. Both the functions return an integer value. The value returned by wherex( ) is the horizontal position of cursor and the value returned by wherey( ) is the vertical position of the cursor. Following program shows how to use the wherex( ) and wherey( ) functions.
    #include
    main( )
    {
    printf ( “Just\n To\n Test\n Where\n the cursor\n goes” ) ;

    printf ( “Current location is X: %d Y: %d\n”, wherex( ), wherey( ) ) ;
    }

  3. How do I programmatically delete lines in the text window?
    Ans: While writing programs that perform screen-based I/O, you may want to-delete the current line’s contents, moving one line up, all of the output that follows. In such cases a function called delline( ) can be used. Following code snippet illustrates the use of function delline( ).
    #include
    main( )
    {
    int i ;
    clrscr( ) ;
    for ( i = 0; i <= 23; i++ )
    printf ( “Line %d\r\n”, i ) ;
    printf ( “Press a key to continue : ” ) ;
    getch( ) ;
    gotoxy ( 2, 6 ) ;
    for ( i = 6; i <= 12; i++ )
    delline( ) ;
    getch( ) ;
    }

  4. How do I get the time elapsed between two function calls ?
    Ans: The function difftime( ) finds the difference between two times. It calculates the elapsed time in seconds and returns the difference between two times as a double value.
    #include
    #include
    #include
    main( )
    {
    int a[] = { 2, -34, 56, 78, 112, 33, -7, 11, 45, 29, 6 } ;
    int s ;
    time_t t1, t2 ; // time_t defines the value used for time function
    s = sizeof ( a ) / 2 ;
    t1 = time ( NULL ) ;
    sel_sort ( a, s ) ; // sort array by selection sort
    bub_sort ( a, s ) ; // sort array by bubble sort method
    t2 = time ( NULL ) ;
    printf ( “\nThe difference between two function calls is %f”, difftime (
    t2, t1 ) ) ;
    }
    In the above program we have called difftime( ) function that returns the time elapsed from t1 to t2.

  5. How do I use swab( ) in my program ?
    Ans: The function swab( ) swaps the adjacent bytes of memory. It copies the bytes from source string to the target string, provided that the number of characters in the source string is even. While copying, it swaps the bytes which are then assigned to the target string.
    #include
    #include
    #include
    main ( )
    {
    char *str1 = “hS eesll snsiasl not eh es as oher ” ;
    char *str2 ;
    clrscr( ) ;
    swab ( str1, str2, strlen ( str1 ) ) ;
    printf ( “The target string is : %s\n”, str2 ) ; // output — She sells
    snails on the sea shore
    getch( ) ;
    }

Leave a Reply

© Copyright 2010 Latestexams. All Rights Reserved | Privacy Policy | Terms & Conditions